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 Thread Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Thread Problem" Watch "Thread Problem" New topic
Author

Thread Problem

Krishna Pratap Singh
Greenhorn

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
Bartender

Joined: Sep 08, 2007
Posts: 2693

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
Greenhorn

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

Joined: Oct 21, 2000
Posts: 3901
harsha must have a lot of time on his hands lol


I never took notes in college. That's how I got a 4.0 the first 2 years, and a 3.5 the second two years.
 
 
subject: Thread Problem
 
Threads others viewed
Running threads in Sequence
regding Thread.join
Threads blocking on static method.... or do they?
Thread
Strings
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com