| Author |
How threads work
|
Angus Ferguson
Ranch Hand
Joined: Jun 22, 2012
Posts: 240
|
|
Hi
I have no experience with threads.
Could anyone give an asnwer to the next question, please?
how synchronised methods work in threaded applications, how can they be released?
Thanks
|
 |
Steve Luke
Bartender
Joined: Jan 28, 2003
Posts: 3032
|
|
Start by reading this: http://docs.oracle.com/javase/tutorial/essential/concurrency/
Angus Ferguson wrote:how synchronised methods work in threaded applications, how can they be released?
What does it mean to 'release' a method?
|
Steve
|
 |
Angus Ferguson
Ranch Hand
Joined: Jun 22, 2012
Posts: 240
|
|
Sometimes they are locked waiting for another thread
|
 |
Niraj Jha
Ranch Hand
Joined: Feb 20, 2013
Posts: 38
|
|
|
With the help of wait() and notify() you can handle the release problem.
|
 |
Steve Luke
Bartender
Joined: Jan 28, 2003
Posts: 3032
|
|
Angus Ferguson wrote:Sometimes they are locked waiting for another thread
No, methods don't get locked. They may get 'blocked' that is, not be able to execute as the try to get access to an Object's synchronization lock. But a method is not locked, has no lock of its own, and can't be released.
|
 |
Steve Luke
Bartender
Joined: Jan 28, 2003
Posts: 3032
|
|
Niraj Jha wrote:With the help of wait() and notify() you can handle the release problem.
Only if the problem is related to wait() and notify(). It is unclear that Angus is talking about a problem or just discussing things to learn about them (I assume the second by the type of question). Since Angus has not mentioned wait() or notify() I would not jump to the conclusion that they will help or explain anything, because they are not really related to synchronized methods (except, in that they may be working on the same locks).
|
 |
Mack Wilmot
Ranch Hand
Joined: Jul 27, 2011
Posts: 78
|
|
I think Angus is talking about intrinsic locks. The object's lock is released when a thread is done with the synchronized method or block in the object and another thread can then acquire the lock.
http://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.html
|
 |
 |
|
|
subject: How threads work
|
|
|