问题:测试类中测试调用多线程的接口时发现程序总是会自动结束,根本不管我的子线程状态的那种啊喂,查阅资料发现可能是测试类的机制不支持对多线程的测试:
初始代码如下(为了确保准确,这里加入了sleep):
@Test
public void test2() {
System.out.println("Start......test.........");
FundThread tFundThread = new FundThread();
tTestFundThread.start();
System.out.println("End.......test......");
}
public class TestFundThread extends Thread {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Start..........Thread.........");
}
}
执行结果发现控制台仅输出了:
Start..........test........
End..........test......