在主线程中创建了一个线程,该线程休眠50ms然后给变量i赋值。主线程要等该子线程结束后获得并输出i的值,使程序的输出结果如下: j=10 ,a.i=10 public class Java_2 { public static void main (String args[]) { try { Sleep a = new Sleep (); Thread t = new Thread (a); //*********Found********** t._____________(); t.join(); int j= a.i; System.out.println("j="+j+",a.i="+a.i); } catch (Exception e) {} } } //*********Found********** class Sleep implements _________________{ int i; public void run () { try { //*********Found********** Thread._______________(50); i= 10; } catch(InterruptedException e) {} } }
时间: 2023-07-19 07:54:43 浏览: 80
FutureTask底层实现分析,有了FutureTask主线程要想获得工作线程(异步计算线程)的结果变得比较简单
public class Java_2 {
public static void main (String args[]) {
try {
Sleep a = new Sleep ();
Thread t = new Thread (a);
t.start();
t.join();
int j= a.i;
System.out.println("j="+j+",a.i="+a.i);
} catch (Exception e) {}
}
}
class Sleep implements Runnable{
int i;
public void run () {
try {
Thread.sleep(50); //线程休眠50ms
i= 10;
} catch(InterruptedException e) {}
}
}
阅读全文