本文共 524 字,大约阅读时间需要 1 分钟。
这问题也是很常见的问题,自打 stop不推荐使用后,我们还有别的可以选择的方法吗?
设置一个标志,让其自动return最安全。
- public class T {
- public static void main(String[] args) {
-
- MyThread thread = new MyThread();
- new Thread(thread).start();
-
-
-
- thread.allDone = true;
- }
- }
- class MyThread implements Runnable {
- boolean allDone = false;
- public void run() {
-
-
-
- while (!allDone) {
-
- }
- }
- }
转载地址:http://jgnzn.baihongyu.com/