package castthread; public class ThreadTest { public static void main(String[] args) { Runnable r=new HelloThread() Thread t=new Thread(r) //r=new HelloThread() Thread t=new Thread(r) tstart() tstart() } } class HelloThread implements Runnable { int i; //成员变量 @Override public void run() { int i=; //局部变量 while(true){ Systemoutprintln(number:+thisi++) //调用的是成员变量i此时无止境的执行下去 try { Threadsleep((long) (Mathrandom()*)) } catch (InterruptedException e) { eprintStackTrace() } if(i==){ break; } } } } |