jakarta-eejndiwildflyjava-ee-7managedthreadfactory

"Traditional" threads cannot lookup JNDI names in WildFly


I'm migrating an old application (uses no beans or dependency injection) from Weblogic to WildFly. For the most part, it now works fine. However, it also creates threads in "traditional way" (new Thread()), and these threads cannot lookup JNDI names, meaning database and mailing is not available to them.

It seems that I need to use a managed thread factory to create the threads instead. This way, new threads should be able to still see JNDI names defined in the container. However, I'm not sure how to retrieve such a factory from the container. All examples I could find use dependency injection and the application is written without that at all.

So, how do I access JNDI names from self-created threads? Or, how do I retrieve a managed thread factory I can use to create threads that still see the container and its JNDI bindings?


Solution

  • The standard managed thread factory is available in JNDI using the name java:comp/DefaultManagedThreadFactory.

    See §EE.5.21, page 146 of the Java EE 7 spec for more information.