日期:2014-05-20 浏览次数:20890 次
public class Test{ public static void main(String[] args) throws Exception{ Thread t1 = new Thread(new ThreadTest(10)); t1.start(); Thread t2 = new Thread(new ThreadTest(20)); t2.start(); Thread t3 = new Thread(new ThreadTest(30)); t3.start(); Thread t4 = new Thread(new ThreadTest(40)); t4.start(); Thread t5 = new Thread(new ThreadTest(50)); t5.start(); } } class ThreadTest implements Runnable{ public static int i = 0; public ThreadTest(int i){ ThreadTest.setI(i); } public void run(){ System.out.println(ThreadTest.getI()); } public static int getI() { return i; } public static void setI(int i) { ThreadTest.i = i; } }