L
lyallex
Hi
Hi
Say I have the following (pointless) code
package head;
public class BrainBender{
private SomeClass sc = new SomeClass()
public void a(){
synchronized(Integer.class){
sc.doSomething() // might take a while
}
}
public void b(){
synchronized(Integer.class){
sc.doSomethingElse() //might take a long time
}
}
}
According to my understanding this would have the effect of
synchronizing on the unique Class object for Integer.
This means that regardless of where I used
synchronized(Integer.class) within the same process space it would
have the effect of providing mutual exclusion accross all such
synchronized blocks.
e.g
package garden; //nothing to do with head
public class Compost{
private Worm worm = new Worm();
public void blah(){
synchronized(Integer.class){
// ... access the Worm
}
}
//whatever
}
So if some Thread was currently executing b() in an instance of
BrainBender and this was taking a while, any thread that wanted to
access the Worm would have to wait for the lock on Integer.class
Is this correct ?
many thanks
Lyall
Hi
Say I have the following (pointless) code
package head;
public class BrainBender{
private SomeClass sc = new SomeClass()
public void a(){
synchronized(Integer.class){
sc.doSomething() // might take a while
}
}
public void b(){
synchronized(Integer.class){
sc.doSomethingElse() //might take a long time
}
}
}
According to my understanding this would have the effect of
synchronizing on the unique Class object for Integer.
This means that regardless of where I used
synchronized(Integer.class) within the same process space it would
have the effect of providing mutual exclusion accross all such
synchronized blocks.
e.g
package garden; //nothing to do with head
public class Compost{
private Worm worm = new Worm();
public void blah(){
synchronized(Integer.class){
// ... access the Worm
}
}
//whatever
}
So if some Thread was currently executing b() in an instance of
BrainBender and this was taking a while, any thread that wanted to
access the Worm would have to wait for the lock on Integer.class
Is this correct ?
many thanks
Lyall