单线程中的多个Runnable -java [英] Multiple Runnable in a single thread -java
本文介绍了单线程中的多个Runnable -java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试拥有一堆可以一次启动的可运行线程。
像这样的东西
I am trying to have a bunch of runnable threads that can be started one at a time. Something like
First(new Thread() {
public void run() {
//do something
}
});
我要做什么是不可能的事?
Is what I'm trying to do impossible?
推荐答案
您可以使用单线程执行器
You can use a single threaded Executor
ExecutorService service = Executors.newSingleThreadedPool();
service.submit(runnable1);
service.submit(runnable2);
service.submit(runnable3);
这篇关于单线程中的多个Runnable -java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文