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 ?