File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes How to Manage Thread wait and notify 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 to Manage Thread wait and notify" Watch "How to Manage Thread wait and notify" New topic
Author

How to Manage Thread wait and notify

Cheenath Ajay
Ranch Hand

Joined: Jan 26, 2006
Posts: 32
I have Two Threads


Thread 1: Started execution � low priority

Thread 2: In between Thread 1�s execution, Thread 2 also started � high priority


As per the design


Condition 1: Thread 2 execution should suspend Thread 1 execution

Condition 2: After the Thread 2 execution, Thread 1 should resume its suspended execution



Can any one help me on this?



Thanks in advance,


-Ajay Cheenath
Edward Harned
Ranch Hand

Joined: Sep 19, 2005
Posts: 291

Sounds like a home work assignment.

Use wait() and notify() like your question suggests. For how, read the concurrency tutorial, Tutorial


Ed's latest article: A Java Parallel Calamity http://coopsoft.com/ar/Calamity2Article.html
Saurabh Patil
Ranch Hand

Joined: Dec 11, 2005
Posts: 45

The functions in thread class themselves define clearly when and where they should be used and wait() and notify() are no exceptions. Also see notifyAll()


All for one and one for all!
Cheenath Ajay
Ranch Hand

Joined: Jan 26, 2006
Posts: 32
Thanks for your input.
Let me move little ahead with my initial question
What I have is a collection of Thread objects
In certain point of time i need them to execute and some of them to suspend and resume, But here the issue is condition for handling these operations are gathered from different threads,
Means using one thread calling start another for wait and notify
So that java throwing execption complaining this
 
Don't get me started about those stupid light bulbs.
 
subject: How to Manage Thread wait and notify