50,528
社区成员
发帖
与我相关
我的任务
分享
package com.ye;
public class Test3 {
public static void main(String[] args) {
try {
MyThread t = new MyThread();
t.start();
Thread.sleep(100);
t.setStop();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
static class MyThread extends Thread {
private boolean flag = true;
@Override
public void run() {
System.out.println("线程开始。。。。。。。");
while (flag) {
}
System.out.println("线程结束。。。。。。。");
}
public void setStop() {
System.out.println("设置flag=false");
this.flag = false;
}
}
}
package com.ye;
public class Test3 {
public static void main(String[] args) {
try {
MyThread t = new MyThread();
t.start();
Thread.sleep(100);
t.setStop();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
static class MyThread extends Thread {
private boolean flag = true;
@Override
public void run() {
System.out.println("线程开始。。。。。。。");
while (flag) {
System.out.println("-------");
}
System.out.println("线程结束。。。。。。。");
}
public void setStop() {
System.out.println("设置flag=false");
this.flag = false;
}
}
}