Can I run ManagedThread in a Singleton Enterprise Java Bean?

I try to start a thread in Singleton EJB, but it java.lang.IllegalStateExceptionthrows. This is my (cut) class:

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
    } 
}

I assume there is a problem with when I try to run a Thread object or does Java EE 7 not allow managed threads at single points?

0
source share
2 answers

Which application server are you using?

If it's WildFly, you are likely to run into this problem: https://issues.jboss.org/browse/WFLY-2343

0
source
+1

Source: https://habr.com/ru/post/1542258/


All Articles