class MyRunner implements Runnable{
public void run(){
doThis();
}
synchronized void doThis(){
}
}
class Test{
public static void main(
String[] args){
MyRunner r1 = new MyRunner();
MyRunner r2 = new MyRunner();
Thread t1 = new Thread(r1);
Thread t2 = new Thread(r2);
t1.start();
t2.start();
}
}
A few questions related to synchronisation based on the above programme.
1. when you say t1.start(), which object is locked - t1, r1 or 'this'?
2. t2 can't execute doThis() method before t1 completes with it - yes or no? why?
3. does it make a difference to your above answer, if t1 and t2, takes the same argument, r1 in the constructors.
This might help me undertand the synchronizaion better.
Thanks in advance.