Forums Register Login

Threads...

+Pie Number of slices to send: Send
hi can any one answer to this...


How can two threads access a synchronized block simultaneuously i.e. one thread should give the chance for other thread to execute synchronized block even before this thread finishes the execution of the same synchronized block?
+Pie Number of slices to send: Send
 

Originally posted by sumi mathew:

How can two threads access a synchronized block simultaneuously i.e. one thread should give the chance for other thread to execute synchronized block even before this thread finishes the execution of the same synchronized block?



Simple answer... you can't. While a thread is holding a lock, another thread that needs the lock can't execute. That is the whole purpose of synchroniation.

More complex answer.... you can give up the lock within the synchronization block via the wait() method. But if you are going to do that, you will have to work out a wait/notify handshake between the two threads.

Henry
[ May 09, 2008: Message edited by: Henry Wong ]
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 630 times.
Similar Threads
Synchronized block doubt
Synchronization And Locks
Synchronized method and Sychronized block
hello i am mohandodderi very new member in the family
Difference between synchronizing a method and synchronizing a block of code in the method
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:54:33.