日期:2014-05-20 浏览次数:20835 次
public class TestSync implements Runnable{ Timeer T = new Timeer(); public static void main(String[] args) { TestSync test = new TestSync(); Thread t1 = new Thread(test); Thread t2 = new Thread(test); t1.setName("t1"); t2.setName("t2"); t1.start(); t2.start(); } public void run(){ //System.out.println(Thread.currentThread().getName()); T.add(Thread.currentThread().getName()); } } class Timeer{ private static int num = 0; public void add(String name){ num++; System.out.println(name+", 你是第"+num+"个使用timer的线程"); } }