package com.Thread;import sun.rmi.runtime.Log;public class Thread0202 extends Thread { public void run() { Thread0201 t1 = new Thread0201(); Thread0201 t2 = new Thread0201(); // 使用Runnable接口創(chuàng)建線程 Thread one = new Thread(new Thread0201(), "one"); Thread two = new Thread(new Thread0201(), "two"); one.start(); two.start(); // 為什么start一開始 下面的命令不會執(zhí)行 而且廝殺過程一直不會停止 try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } t1.i = false; t2.i = false; try { two.join(); } catch (InterruptedException e) { e.printStackTrace(); } } public static void main(String[] args) { new Thread0202().start(); }}
1 回答
已采納

qq_青棗工作室_0
TA貢獻(xiàn)446條經(jīng)驗 獲得超754個贊
因為你start的線程沒有用到t1和t2啊。
//?使用Runnable接口創(chuàng)建線程 Thread?one?=?new?Thread(new?Thread0201(),?"one");????//?這里你new了一個Thread0201,應(yīng)該用t1 Thread?two?=?new?Thread(new?Thread0201(),?"two");??//?這里你new了一個Thread0201,應(yīng)該用t2
添加回答
舉報
0/150
提交
取消