本帖最后由 秦兰之 于 2013-8-7 20:10 编辑
- package extendThread;
- public class StopThread implements Runnable
- {
- private boolean flag = true;
- @Override
- public void run()
- {
- while (flag)
- {
- System.out.println(Thread.currentThread().getName()+"......run");
- }
- }
- public void changFlag()
- {
- flag=false;
- }
- }
复制代码- package extendThread;
- class StopThreadDemo{
- public static void main(String[] args)
- {
- StopThread stopThread = new StopThread();
-
- Thread t1= new Thread(stopThread);
- Thread t2= new Thread(stopThread);
-
- t1.setDaemon(true);
- t2.setDaemon(true);
- t1.start();
- t2.start();
-
- int num=0;
-
- while (true)
- {
- if (num++ == 60)
- {
- /*stopThread.changFlag();
- t1.interrupt();
- t2.interrupt();*/
- break;
- }
- System.out.println(Thread.currentThread().getName()+"......"+num);
- }
- System.out.println("over");
-
- }
- }
复制代码 在dos命令行两段代码是合在一起的,在Eclipse分开了,Eclipse 为啥执行不了? |