0
votes

I have an environment where one EJB starts at the server startup, the code internally calls another stateless bean, which internally starts a thread via Executor Service. In this thread started via Executor Service, whenever i do a jndi lookup (java:global/testing/NetworkConnectionChecker!com.testing.common.NetworkConnectionChecker) inside run method, i get javax.naming.NameNotFoundException but if i put a thread.sleep for around 60 seconds in the run method of this thread, the jndi lookup gives me the object, and no exception is thrown. One more interesting point, is that when i do the lookup in the constructor of the Thread which I started, i get the object via jndi lookup right away, without putting any Thread.sleep The EJB which i am trying to obtain via jndi lookup is annotated as @Singleton and @Startup. Can anyone suggest me, what i am doing wrong, I can also see the logs generated on server startup mentioning the jndi binding. The log is as follows

(name=global/testing/NetworkConnectionChecker!com.testing.common.NetworkConnectionChecker)

I see the following exception when jndi lookup fails

javax.naming.NameNotFoundException: Name [global/testing/NetworkConnectionChecker!com.testing.common.NetworkConnectionChecker] is not bound in this Context. Unable to find [global].
at org.apache.naming.NamingContext.lookup(NamingContext.java:819)
at org.apache.naming.NamingContext.lookup(NamingContext.java:167)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:156)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.testing.main.AbstractServiceFactory.getNetworkConnectionChecker(AbstractServiceFactory.java:85)

I am using java 8 and tomee version 1.7

Please let me know if any of you require any more information. I have spent one entire day trying to figure it out.

1

1 Answers