Guest User

Untitled

a guest
Oct 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. package multithreading;
  2.  
  3. public class Main {
  4.  
  5. final static int THREAD_COUNT = 3;
  6. final static String[] THREAD_NAMES = {"A", "B", "C"};
  7.  
  8. public static void main(String[] args) {
  9.  
  10. for(int i = 0; i < THREAD_COUNT; i++) {
  11. Multithreading thread = new Multithreading();
  12. thread.setName(THREAD_NAMES[i]);
  13. thread.start();
  14. }
  15. }
  16. }
  17.  
  18. class Multithreading extends Thread {
  19.  
  20. public void run() {
  21.  
  22. int x;
  23. int sum = 0;
  24. for(x = 1; x < 9; x++) {
  25. sum += x;
  26. }
  27. sum += x;
  28.  
  29. String threadName = Thread.currentThread().getName();
  30. System.out.println(String.format("Thread : %s - value : %d", threadName, sum));
  31. }
  32. }
Add Comment
Please, Sign In to add comment