|
What this is
Other links
The source code/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.openide.filesystems;
import junit.framework.*;
import org.netbeans.junit.*;
/**
* A multi-threaded JUnit test case.
*
*/
public class MultiThreadedTestCaseHid extends NbTestCase {
/**
* The threads that are executing.
*/
private Thread threads[] = null;
/**
* The tests TestResult.*/
private TestResult testResult = null;
/**
* Simple constructor.
*/
public MultiThreadedTestCaseHid(String s) {
super(s);
}
/**
* Interrupt the running threads.
*/
public void interruptThreads() {
if(threads != null) {
for(int i = 0;i < threads.length;i++) {
//System.out.println("interrupted");
threads[i].interrupt();
}
}
}
/**
* Override run so we can squirrel away the test result.*/
public void run(final TestResult result) {
testResult = result;
super.run(result);
testResult = null;
}
/**
* Run the test case threads.*/
protected void runTestCaseRunnables (final TestCaseRunnable[] runnables, int ms) {
if(runnables == null) {
throw new IllegalArgumentException("runnables is null");
}
threads = new Thread[runnables.length];
for(int i = 0;i < threads.length;i++) {
threads[i] = new Thread(runnables[i]);
}
for(int i = 0;i < threads.length;i++) {
threads[i].start();
}
try {
long start = System.currentTimeMillis();
for(int i = 0;i < threads.length;i++) {
if (System.currentTimeMillis()-start > ms ) {
interruptThreads();
throw new InterruptedException ("Time ammount elapsed: probably deadlock.");
}
threads[i].join((ms - (System.currentTimeMillis()-start)),0);
}
}
catch(InterruptedException ignore) {
handleException(ignore);
}
threads = null;
}
/**
* Handle an exception. Since multiple threads won't have their
* exceptions caught the threads must manually catch them and call
*
|
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.