Link to home
Start Free TrialLog in
Avatar of Jay Roy
Jay RoyFlag for United States of America

asked on

synchronized with subclass

hi guys

Object2 extends Object1

public class MyClass{
...
Object1 object1 = new Object1();
Object2 object2 = new Object2();
.....
....
synchronized( object1){
  // code 1
}

//code 2
synchronized( object 2){
  // code 3
}
}

When thread t1 executes code1, can thread t2 execute code3 at the same time?

thanks.
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The below, however, would result in only one code block being able to be executed at a time... (just to point out that it needs to be the same actual object that the synchronization works on, even this one object has to variables the refer to it)

Object2 object2 = new Object2();
Object1 object1 = object2;