|
-
Nov 23rd, 2009, 01:30 AM
#1
Thread Starter
Frenzied Member
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.
-
Nov 23rd, 2009, 05:36 AM
#2
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;
}
}
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 23rd, 2009, 08:37 PM
#3
Thread Starter
Frenzied Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|