Results 1 to 2 of 2
- 01-03-2010, 04:44 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 4
- Rep Power
- 0
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, 10:22 PM #2
so that no thread can access this part of the code until the other has finished it's output and input
Study the producer–consumer example on Guarded Blocks.
Similar Threads
-
What will be output by the following code? using trim method.
By racewithferrari in forum New To JavaReplies: 4Last Post: 11-17-2009, 09:40 PM -
Create code for Binary Search Tree using compareTo method using I/O
By harvin23 in forum New To JavaReplies: 5Last Post: 10-13-2009, 01:35 PM -
Trouble implementing part of code into GUI
By Flaresplitz in forum New To JavaReplies: 1Last Post: 12-21-2008, 07:51 AM -
Disabling part of a method
By juru in forum Advanced JavaReplies: 10Last Post: 10-27-2008, 01:41 AM -
Netbeans 6.0 - code completion of method parameters
By mwildam in forum NetBeansReplies: 9Last Post: 12-18-2007, 09:02 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks