更新时间:2022-09-15 19:16:27
/**
*
*/
package com.dtsz.groboTest;
import net.sourceforge.groboutils.junit.v1.TestRunnable;
/**
* @author xiaoli
*
*/
public class TestRunnable1 extends TestRunnable {
private int i;
private long sleepTime;
public TestRunnable1(int i ,long sleepTime) {
super();
this.i = i;
this.sleepTime = sleepTime;
}
/* (non-Javadoc)
* @see net.sourceforge.groboutils.junit.v1.TestRunnable#runTest()
*/
@Override
public void runTest() throws Throwable {
// TODO Auto-generated method stub
System.out.println(i+"线程正在跑…………");
this.delay(sleepTime);
System.out.println(i+"线程正要走完…………");
}
}
|
/**
*
*/
package com.dtsz.groboTest;
import net.sourceforge.groboutils.junit.v1.TestMonitorRunnable;
import net.sourceforge.groboutils.junit.v1.TestRunnable;
/**
* @author xiaoli
*
*/
public class TestMonitorRunnable1 extends TestMonitorRunnable {
private int i;
private TestRunnable t;
public TestMonitorRunnable1(int i,TestRunnable t) {
super();
this.i = i;
this.t = t;
}
/* (non-Javadoc)
* @see net.sourceforge.groboutils.junit.v1.TestMonitorRunnable#runMonitor()
*/
@Override
public void runMonitor() throws Throwable {
System.out.println(i+"线程监控正在跑…………状态:"+t.isDone());
}
}
|
/**
*
*/
package com.dtsz.groboTest;
import junit.framework.TestCase;
import net.sourceforge.groboutils.junit.v1.MultiThreadedTestRunner;
import net.sourceforge.groboutils.junit.v1.TestMonitorRunnable;
import net.sourceforge.groboutils.junit.v1.TestRunnable;
import org.junit.Test;
/**
* @author xiaoli
*
*/
public class MainTest1 extends TestCase{
@Override
protected void setUp() throws Exception {
// TODO Auto-generated method stub
super.setUp();
System.out.println("setUp()数据准备");
}
@Override
protected void tearDown() throws Exception {
// TODO Auto-generated method stub
super.tearDown();
System.out.println("tearDown()结束");
}
@Test
public void test1() throws Throwable {
int count = 2;
long time = 0;
TestRunnable[] tr = new TestRunnable[count];
TestMonitorRunnable [] trm = new TestMonitorRunnable[count];
for(int i = 0;i<count;i++) {
TestRunnable1 t = new TestRunnable1(i,(i+1)*time);
TestMonitorRunnable1 m = new TestMonitorRunnable1(i,t);
tr[i] = t;
trm[i] = m;
}
MultiThreadedTestRunner mttr = new MultiThreadedTestRunner(tr,trm);
//没有在该时间内完成的线程将会被杀掉
mttr.runTestRunnables();
}
}
|