简体   繁体   English

如何停止一个线程并调用另一个

[英]How to stop a thread and invoke another

My program running on a one thread. 我的程序在一个线程上运行。 And I have another thread and I want to stop current thread and invoke the second thread. 我有另一个线程,我想停止当前线程并调用第二个线程。 And after second thread stops I want to invoke the first thread again. 在第二个线程停止后,我想再次调用第一个线程。 How can I do this. 我怎样才能做到这一点。 Please help me. 请帮我。

You're looking for Thread.join method 您正在寻找Thread.join方法

like this (thread2 is the other thread you wanna wait for) 这样(thread2是您要等待的另一个线程)

thread2.start();
thread2.join();
System.out.println("Done");

Use public final void join(long ms); 使用public final void join(long ms); method. 方法。 Invoke it in your current thread. 在您当前的线程中调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM