开发者

How to stop a thread and invoke another

开发者 https://www.devze.com 2023-03-31 01:31 出处:网络
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 thre开发者_开发技

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 thre开发者_开发技巧ad again. How can I do this. Please help me.


You're looking for Thread.join method

like this (thread2 is the other thread you wanna wait for)

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


Use public final void join(long ms); method. Invoke it in your current thread.

0

精彩评论

暂无评论...
验证码 换一张
取 消