Fine grained multithreading
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   santhoshi_Alexander
Posted On:   Thursday, April 23, 2009 08:07 AM

In the below example when we synchronize on lock1 and lock2, does it acquire lock on all the objects and methods inside the block. How is it different from synchronized(c1). Why is there an explicit object lock1 and lock2 public class MsLunch { private long c1 = 0; private long c2 = 0; private Object lock1 = new Object(); private Object lock2 = new Object(); public void inc1() { synchronized(lock1) { c1++; } } public void inc2() { synchronized(lock2) { c2++; } } }    More>>

In the below example when we synchronize on lock1 and lock2, does it
acquire lock on all the objects and methods inside the block. How is
it different from synchronized(c1).
Why is there an explicit object lock1 and lock2

			
public class MsLunch {
private long c1 = 0;
private long c2 = 0;
private Object lock1 = new Object();
private Object lock2 = new Object();

public void inc1() {
synchronized(lock1) {
c1++;
}
}

public void inc2() {
synchronized(lock2) {
c2++;
}
}
}
   <<Less
About | Sitemap | Contact