tec
tec

Reputation: 41

Running thread for 2 millisecond and then wait for particular time before running it again

I have one method execute(data) which takes considerable time (depending on data like 10 seconds or 20 seconds), it has timeout feature which is 30 seconds default. I want to test that method. One way of doing it is to collect enough data which lasts more than 30 seconds and then see whether I get timeout exception. Other way of doing it is to use threads. What I intend to do is to run method for some milliseconds and then put thread on wait before I get timeout exception or make it last for some seconds.Can any one please suggest how can I achieve that.

Upvotes: 0

Views: 671

Answers (2)

slipperyseal
slipperyseal

Reputation: 2778

You could use

Thread.sleep( millis );

to put the thread to sleep for the required time.

Or, you could put your data processing code into a loop, so that it processes it multiple times. This would recreate the scenario of the thread actually processing data for longer than 30 seconds.

Or, you could test your code with a shorter timeout value.

Upvotes: 0

Dean J
Dean J

Reputation: 40369

You should walk through the Java Threads Tutorial (Concurrency). Any answer on Stack Overflow would need to be really long to help you here, and the Threads/Concurrency tutorials already cover this well.

http://docs.oracle.com/javase/tutorial/essential/concurrency/

Upvotes: 1

Related Questions