aspose file tools*
The moose likes Threads and Synchronization and the fly likes How threads work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "How threads work" Watch "How threads work" New topic
Author

How threads work

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 389
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: 4181
    
  21

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
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 389
Sometimes they are locked waiting for another thread

Niraj Jha
Ranch Hand

Joined: Feb 20, 2013
Posts: 63

With the help of wait() and notify() you can handle the release problem.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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: 4181
    
  21

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: 88

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://aspose.com/file-tools
 
subject: How threads work