I want to implement the following Task
1) Read till end of file
2) In each Line of the file there is a time mentioned. You need no call a method( code of which I have already written)
3)Wait for the time mentioned in that line of file and then again read the next line of file

I want to implement this code. It will start when I press a start button and can be stopped in the middle if I press a stop button

Also this time delay mentioned mentioned in the file is approximately 70 ms. I want to avoid using Thread.sleep() in an infinite loop

Is there way a to use Timer class to implement the above code.

7 Years
Discussion Span
Last Post by javaAddict

I would have used the sleep method:

// line read:
line = readLine();

// take the time at the end of the line:
lone time = ... ;

try {
} catch (Exception e) {

// repeat the loop

I would suggest to put the above in a Thread class and start it. When the "stop" button is clicked, you can call the sleep method on the above thread.
Actually I don't know if you can do that, but if you check the API you will find a method that will cause your thread to wait. Maybe the 'wait' method.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.