In our code the lookup for the bean manager isn't directly the first call using the lambda expression within the parallel stream. It is being called in a class that is also used by other methods in other threads. I don't want to share the bean manager within the for/join-pool threads but because the code structure the lookup is necessary at a specific point.
Maybe follow code snippet and the error trace will show what I mean:
Code _queryDocResults.parallelStream().forEach(r -> createDocumentEntry(r.getXdsObjectObjId(), r.getXdsObjectUUID(), r.getHome()));
Stack Trace java.lang.RuntimeException: Couldn't get BeanManager through JNDI Lookup at marabu.common.tools.CDIHelper.getCDIInstance(CDIHelper.java:31) at marabu.pegasos.server.ihe.xds_b.tools.XDSInfosetHelper.createPatientIdExternalIdentifier(XDSInfosetHelper.java:721) at marabu.pegasos.server.ihe.xds_b.core.spi.metadata.XDSDocumentEntry.<init>(XDSDocumentEntry.java:280) at marabu.pegasos.server.ihe.xds_b.core.service.helper.query.registry.AbstractQuery.createDocumentEntry(AbstractQuery.java:637) at marabu.pegasos.server.ihe.xds_b.core.service.helper.query.registry.AbstractQuery.lambda$buildQueryResponseObjects$4(AbstractQuery.java:572) at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291) at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) Caused by: javax.naming.NameNotFoundException: java:comp/BeanManager at javax.naming.InitialContext.lookup(InitialContext.java:417) at javax.naming.InitialContext.lookup(InitialContext.java:417) at javax.naming.InitialContext.doLookup(InitialContext.java:290) at marabu.common.tools.CDIHelper.getCDIInstance(CDIHelper.java:28) ... 13 more
Within the method XDSInfosetHelper.createPatientIdExternalIdentifier() the lookup for the bean manager is needed because the XDSInfosetHelper is not a managed bean instance. In the class CDIHelper the lookup is done. I use this helper class when I don't have a managed bean as source but I want to access a managed bean. The error is the same as I would write follow:
_Thread th = new Thread() {
public void run() { InitialContext.doLookup("java:comp/BeanManager"); }
};_
As described in the weld documentation the Bean Manager is only available in a managed environment. When I would use a managed thread this the lookup would work. But I can't create a Managed Thread when using the ForkJoinPool.
|