Results 1 to 2 of 2
- 01-03-2010, 05:44 PM #1Member
- Join Date
- Dec 2009
- Rep Power
Sychronizing a part of a code in a method
In the run() method of a thread, there is a line where the user is asked to enter some values (these values are different from thread to thread according to the user's input).
I have a problem in running this program, when multiple threads are started, that line is printed for each thread one after the other giving no chance for the user to enter the value for each thread.
I don't want to add a sleep(), I thought of making a kind of a lock to this part of the code in the method, so that no thread can access this part of the code until the other has finished it's output and input.
So can you help me implement this ? I've seen codes for synchronized methods, but it's not a method, it's just two lines in the method. Any idea how i can do this ?
- 01-03-2010, 11:22 PM #2
- By racewithferrari in forum New To JavaReplies: 4Last Post: 11-17-2009, 10:40 PM
- By harvin23 in forum New To JavaReplies: 5Last Post: 10-13-2009, 02:35 PM
- By Flaresplitz in forum New To JavaReplies: 1Last Post: 12-21-2008, 08:51 AM
- By juru in forum Advanced JavaReplies: 10Last Post: 10-27-2008, 02:41 AM
- By mwildam in forum NetBeansReplies: 9Last Post: 12-18-2007, 10:02 AM