wood burning stoves
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
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

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 Reactive Generator http://coopsoft.com/ar/ReactiveArticle.html
Saurabh Patil
Ranch Hand

Joined: Dec 11, 2005
Posts: 47

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()

Preparing for OCPJWCD 6.
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
I agree. Here's the link: http://aspose.com/file-tools
subject: How to Manage Thread wait and notify
jQuery in Action, 3rd edition