File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes Thread Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread Problem" Watch "Thread Problem" New topic

Thread Problem

Krishna Pratap Singh

Joined: Oct 17, 2010
Posts: 4
I have been trying to solve a problem involving thread communication using wait() and notify(). Basically i have 2 threads T1 and T2 and i want them to be executed in the following order

T1 , T2, T1, T2 ..... How can i achieve that?

Actual Problem: There are 2 threads T1 - which prints odd numbers (say 1 - 100) and T2 - which prints even numbers (1 - 100). Now, the output should be 1, 2, 3, 4 , 5 , .... 100
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
Here is the code
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3119

Harsha Smith wrote:Here is the code <code>

Please dont provide the complete code/solution.

You can help by providing hints on how to proceed with the solution.

Mohamed Sanaulla | My Blog
Krishna Pratap Singh

Joined: Oct 17, 2010
Posts: 4
Thank you very much Harsha , It is working properly.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347

harsha must have a lot of time on his hands lol

Visit my download page
I agree. Here's the link:
subject: Thread Problem