
2 RET指令会将子程序的返回地址d出堆栈,并跳转到该地址执行主程序。
3 在主程序中,可以继续执行下一条指令,完成整个程序的执行。
java创建的线程在调用start方法后,进入就绪状态,但通常不会马上分配到CPU,处于线程就绪队列,需要等待时间片轮转到该线程获得CPU后才能执行。
如果你需要先执行新的线程,可以使用Thread类的join方法来等待该线程终止后,再继续往下执行,下面举个代码例子:
public class Test {int i = 0
public static void main(String[] args) {
Test test = new Test()
MyThread1 myThread = new MyThread1(test)
Thread thread = new Thread(myThread)
thread.start()
try {
thread.join()//如果不调用此方法,打印结果为0
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace()
}
System.out.println(test.i)
}
}
class MyThread1 implements Runnable{
Test test
public MyThread1(Test test){
this.test = test
}
@Override
public void run() {
test.i = 1
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)