-
Threaded Timer Class
I need to create a threaded timer class.
This class will start at each junit test and end when the test complete, but if the test does not complete in a certain time interval, it should fail the test.
Still very green to Java, so any help would be appreciated.
-
Re: Threaded Timer Class
Something like this might work
Code:
public class Test
{
private volatile Thread th;
public Test(final int timeout)
{
th = new Thread(new Runnable()
{
@Override
public void run()
{
try
{
Thread.sleep(timeout);
assert false;
}
catch (final InterruptedException e)
{
e.printStackTrace();
assert false;
}
}
});
th.start();
}
public void complete()
{
th = null;
}
}
-
Re: Threaded Timer Class
Thanks!
I did not use it (found the @Test annotation in jUnit have a timeout property, so been using that).
But do have to get to threading sooner or later (as I've switched to Java), so this will be helpful.