- class Test extends Thread{
- private boolean flag ;
-
- public void setStar(){
- flag = true;
- }
-
- public void setEnd(){
- flag = false;
- }
-
- public void run() {
- int num = 0;
- while(flag){
- System.out.println(Thread.currentThread().getName()+" "+num+++" "+flag);
- }
- }
- }
- public class ThreadDemo {
- public static void main(String[] args) {
- Test t = new Test();
- t.setStar();
- t.start();
- for(int i =0;i<=100;i++){
- System.out.println(Thread.currentThread().getName()+" "+i++);
- if(i==60){
-
- t.setEnd();
- }
- }
- }
- }
复制代码 为什么停不下来
|