Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How threads work

 
Isaac Ferguson
Ranch Hand
Posts: 839
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Isaac Ferguson
Ranch Hand
Posts: 839
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes they are locked waiting for another thread

 
Niraj Jha
Ranch Hand
Posts: 63
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the help of wait() and notify() you can handle the release problem.
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
Linux Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic