Skip to content

Instantly share code, notes, and snippets.

@witchica
Created October 25, 2018 09:31
Show Gist options
  • Save witchica/2e1a19f775040fb2ef5c414568582d44 to your computer and use it in GitHub Desktop.
Save witchica/2e1a19f775040fb2ef5c414568582d44 to your computer and use it in GitHub Desktop.
package sqrt;
public class Threads {
public static void main(String[] args)
{
SumThread a = new SumThread("A");
SumThread b = new SumThread("B");
SumThread c = new SumThread("C");
a.start();
b.start();
c.start();
}
public static class SumThread extends Thread
{
public SumThread(String name)
{
super();
this.setName(name);
}
public void run()
{
super.run();
int sum = 0;
for(int x = 0; x < 10; x++)
{
sum += x;
System.out.println(String.format("Thread : %s - Value : %d", Thread.currentThread().getName(), sum));
}
System.out.println(String.format("Thread : %s - Sum : %d", Thread.currentThread().getName(), sum));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment