This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Manage Thread wait and notify

 
Cheenath Ajay
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 291
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a home work assignment.

Use wait() and notify() like your question suggests. For how, read the concurrency tutorial, Tutorial
 
Saurabh Patil
Ranch Hand
Posts: 48
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()
 
Cheenath Ajay
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic