import java.awt.EventQueue; public class TestInvokeLater { public static class V extends Thread{ int i; public V(int i){this.i = i;} public void run() { try{ System.out.println("doing" + i); Thread.sleep(3000l); System.out.println("done" + i); // new V(10+i).start(); //本行为再新建子线程,下行为转为主线程同步 EventQueue.invokeLater( new V(10+i)); } catch (Exception e) { // TODO: handle exception } } } public static void main(String[] args) throws Exception{ new V(1).start(); new V(2).start(); new V(3).start(); Thread.sleep(5000l); } }
发表于 28/11/2012 , 02:34 于分类 Java.