I am having my application deployed in EJBContainer in glassfish server. I am calling one method using Callable and future in session bean, and in this method i'm using EntityManager for some transaction but getting an NullPointerException for whenever any call to EntityManager is there. Below is the error stack trace::

 Severe:   java.lang.NullPointerException
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.getNonTxEMsFromCurrentInvocation(EntityManagerWrapper.java:276)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.getNonTxEMFromCurrentInvocation(EntityManagerWrapper.java:260)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:213)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createQuery(EntityManagerWrapper.java:455)
at LogisticsEngineSessionBean.getAllPackSerialsForProcess(LogisticsEngineSessionBean.java:3137)
at LogisticsEngineSessionBean.processSalesOutLines(LogisticsEngineSessionBean.java:3462)
at LogisticsEngineSessionBean.lambda$updateSKULocationStatusOnSell$0(LogisticsEngineSessionBean.java:2972)
at LogisticsEngineSessionBean$$Lambda$7/1138463255.call(Unknown Source)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
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:1689)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

Please suggest whether it is because i'm trying to do multi threading or any alternate for this is available. I'm using EclipseLink JPA. This NullPointerException is not within my Code,it is coming in EntityManager which is working fine when i'm not doing MultiThreading. And EntityManager Object is not null, Please read the question properly before giving downvote.


这与您的容器有关,而不是您的 JPA 提供程序 - EM 包装器不为空,但它下面的上下文是。EntityManagers 无论如何都不是线程安全的,因此每个线程都需要自己的线程。

那么我该怎么做才能纠正这个问题,我需要这个可调用的功能来更好地处理,因为我正在处理大量数据。我该怎么做才能将事务上下文放在那里。