This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes How threads work Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "How threads work" Watch "How threads work" New topic
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
    
    4

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
    
    4

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
    
    4

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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How threads work
 
Similar Threads
how many for each one?
Threading
Two threads of same class instance to wait separately
how to highlight Highlight One Specific line/Row in a JTextArea
threads