Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Increment extends Thread{
- static Integer i=new Integer(0);
- public void run(){
- for(int j=1;j<=1000;j++){
- synchronized (i) {
- i++;
- }
- }
- }
- }
- public class Puzzle {
- public static void main(String args[]) {
- Thread t1=new Increment();
- Thread t2=new Increment();
- t1.start();
- t2.start();
- try {
- t1.join();
- t2.join();
- }catch (InterruptedException r){}
- System.out.println(Increment.i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement