Guest User

Untitled

a guest
Oct 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. class RunnableDemo implements Runnable {
  2. private Thread t;
  3. private String threadName;
  4.  
  5. RunnableDemo( String name) {
  6. threadName = name;
  7.  
  8. }
  9.  
  10. public void run() {
  11. int x=1;
  12. int sum=0;
  13. for(int y=0;y<10;y++)
  14. {
  15. sum+=y;
  16. }
  17. x+=sum;
  18. System.out.println("Thread : "+threadName+" - value : "+x);
  19. }
  20.  
  21. public void start () {
  22.  
  23. if (t == null) {
  24. t = new Thread (this, threadName);
  25. t.start ();
  26. }
  27. }
  28. }
  29.  
  30. public class TestThread {
  31.  
  32. public static void main(String args[]) {
  33. RunnableDemo A = new RunnableDemo( "A");
  34. A.start();
  35.  
  36. RunnableDemo B = new RunnableDemo( "B");
  37. B.start();
  38. RunnableDemo C = new RunnableDemo( "C");
  39. C.start();
  40. }
  41. }
Add Comment
Please, Sign In to add comment