Created
October 25, 2018 09:31
-
-
Save witchica/2e1a19f775040fb2ef5c414568582d44 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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