我试图在Singleton中启动一个线程,但是抛出了java.lang.IllegalStateException。这是我的(削减)课程:
Singleton
@LocalBean
@Startup
public class WatcherEJB {
@Resource(name = "concurrent/masterActionsThreadFactor")
ManagedThreadFactory threadFactory;
Thread watcherThread;
@PostConstruct
public void startUp() {
//Setup the listener using the ThreadFactory
watcherThread = threadFactory.newThread(new Runnable() {
@Override
public void run() {
//System.out.println("Watcher Thread started");
}
});
watcherThread.start(); //java.lang.IllegalStateException thrown here
}
}我假设当我试图启动Thread对象时会出现问题,还是Java 7不允许单例中的托管线程?
发布于 2013-12-09 12:47:37
您使用什么应用服务器?
如果是WildFly,您可能会遇到以下问题:https://issues.jboss.org/browse/WFLY-2343
发布于 2015-03-17 09:44:08
我在寻找解决方案的时候遇到了这个帖子,我想我会把这个链接发到一个我认为能回答问题的帖子上。我知道这个问题提出已经有一段时间了,但它应该是有用的,以供今后参考!
Glassfish 4 - Using Concurrency API to create Managed Threads
https://stackoverflow.com/questions/20446682
复制相似问题