SCJP 1.6, SCWCD 5.0, SCBCD 5.0 [loading..]
All code in my posts, unless a source is explicitly mentioned, is my own.
SCJP 1.6, SCWCD 5.0, SCBCD 5.0 [loading..]
Himalay Majumdar wrote:Ruben
I am not expecting Thread.sleep to release lock, it was just to make sure it works for more time on display2()..so that in the meantime Thread-2 executes display1().
Isnt it the case that Thread-1 should release the lock from display1() after executing.
Here Thread-1 is executing both the synchronized methods display1() and display2() and then only allowing Thread-2 to start executing
What I am thinking is ..when Thread-1 is done executing display1(), Thread-2 should be given a chance immediately. So that..Thread-2 works on display1() and Thread-1 works on display2() simultaneously.
All code in my posts, unless a source is explicitly mentioned, is my own.
SCJP 1.6, SCWCD 5.0, SCBCD 5.0 [loading..]
All code in my posts, unless a source is explicitly mentioned, is my own.
Banu Chowdary wrote: Why it is not possible for another thread to enter display1(); after first thread has been completed. and the first thread before entering display2() second thread can enter display1();
Ruben wrote: In your original code it is possible that Thread-2 might be selected by the scheduler to run as soon as Thread-1 finishes executing display1() and before it starts executing display2(). It's not very likely though.
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
SCJP 1.6, SCWCD 5.0, SCBCD 5.0 [loading..]
All code in my posts, unless a source is explicitly mentioned, is my own.
SCJP 1.6, SCWCD 5.0, SCBCD 5.0 [loading..]