Advertisement
Guest User

letifcik

a guest
Oct 15th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. Object o = new Object();
  2.  
  3. Thread t1 = new Thread() {
  4.  
  5. public void run() {
  6. synchronized(o) {
  7. for(int i=0; i<1000; i++) {
  8. System.out.print(" " +i+ " AAAA");
  9. // System.out.println(" letif");
  10. }
  11. System.out.println("");
  12.  
  13. }
  14. }
  15.  
  16. };
  17.  
  18. Thread t2 = new Thread() {
  19. public void run() {
  20. synchronized(o) {
  21. for(int i=0; i<1000; i++) {
  22. System.out.print(" " +i+ " BBBB");
  23. // System.out.println(" letif");
  24. }
  25. System.out.println("");
  26.  
  27. }
  28. }
  29. };
  30.  
  31.  
  32.  
  33.  
  34. try {
  35. t1.start();
  36. t1.join();
  37. t2.start();
  38. t2.join();
  39. } catch (InterruptedException e) {
  40. // TODO Auto-generated catch block
  41. e.printStackTrace();
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement