junit多线程测试,子线程会随主线程结束而结束。而main方法内的子线程不会结束
public class mytest { @Test public void fun(){ new Thread(new Runnable() { @Override public void run() { try { TimeUnit.SECONDS.sleep(10); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); new Thread(new Runnable() { @Override public void run() { try { TimeUnit.SECONDS.sleep(10); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); System.out.println("junit thread end!"); } public static void main(String[] args) { new Thread(new Runnable() { @Override public void run() { try { TimeUnit.SECONDS.sleep(10); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); new Thread(new Runnable() { @Override public void run() { try { TimeUnit.SECONDS.sleep(10); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); System.out.println("main thread end!"); } }