Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. class Increment extends Thread{
  2. static Integer i=new Integer(0);
  3.  
  4. public void run(){
  5.  
  6. for(int j=1;j<=1000;j++){
  7. synchronized (i) {
  8. i++;
  9. }
  10. }
  11.  
  12. }
  13. }
  14.  
  15.  
  16. public class Puzzle {
  17. public static void main(String args[]) {
  18. Thread t1=new Increment();
  19. Thread t2=new Increment();
  20. t1.start();
  21. t2.start();
  22. try {
  23. t1.join();
  24. t2.join();
  25. }catch (InterruptedException r){}
  26. System.out.println(Increment.i);
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement