我试图从tread调用一些ejb bean方法。以及获取错误:
(与GlassFish v3一样)
日志级别
严重记录器
javax.enterprise.system.std.com.sun.enterprise.v3.services.impl
名称-值对
{u threadname=thread-1,{u threadid=42}
记录号928消息ID
位于的java.lang.NullPointerException
ua.co.rufuss.server.broker.templicservice.run(templicservice.java
完成信息35)在
Java.UTI.Orth.TycRePoLeExtor的$Works.RunTube(TythPoLeExcel)。Java:886)
在
Java.UTI.Orth.TycRePoLeExtor的$Works.Run(TythPoLeExcel)。Java:908)
在
Java.Lang.Tr.Run(线程.java:637)
这是特蕾德
public class TempLicService implements Runnable {
String hash;
//it`s Stateful bean
@EJB
private LicActivatorLocal lActivator;
public TempLicService(String hash) {
this.hash= hash;
}
@Override
public void run() {
lActivator.proccessActivation(hash);
}
}
我的线程池执行器
public class RequestThreadPoolExecutor extends ThreadPoolExecutor {
private boolean isPaused;
private ReentrantLock pauseLock = new ReentrantLock();
private Condition unpaused = pauseLock.newCondition();
private static RequestThreadPoolExecutor threadPool;
private RequestThreadPoolExecutor() {
super(1, Integer.MAX_VALUE, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
System.out.println("RequestThreadPoolExecutor created");
}
public static RequestThreadPoolExecutor getInstance() {
if (threadPool == null)
threadPool = new RequestThreadPoolExecutor();
return threadPool;
}
public void runService(Runnable task) {
threadPool.execute(task);
}
protected void beforeExecute(Thread t, Runnable r) {
super.beforeExecute(t, r);
pauseLock.lock();
try {
while (isPaused) unpaused.await();
} catch (InterruptedException ie) {
t.interrupt();
} finally {
pauseLock.unlock();
}
}
public void pause() {
pauseLock.lock();
try {
isPaused = true;
} finally {
pauseLock.unlock();
}
}
public void resume() {
pauseLock.lock();
try {
isPaused = false;
unpaused.signalAll();
} finally {
pauseLock.unlock();
}
}
public void shutDown() {
threadPool.shutdown();
}
//<<<<<< creating thread here
public void runByHash(String hash) {
Runnable service = new TempLicService(hash);
threadPool.runService(service);
}
}
方法(它是gwt servlet,但调用不包含ejb的线程是不可能的):
@Override
public Boolean submitHash(String hash) {
System.out.println("submiting hash");
try {
if (tBoxService.getTempLicStatus(hash) == 1) {
//<<< here is the call
RequestThreadPoolExecutor.getInstance().runByHash(hash);
return true;
}
} catch (NoResultException e) {
e.printStackTrace();
}
return false;
}
我需要组织一些提交哈希到服务器的池(licactivator bean的调用),它是
线程池
设计好的想法,为什么在我的情况下不起作用?(我知道我们不能在bean中创建线程,但是我们可以从不同的线程调用bean吗?).
如果没有,巴斯特的做法是什么?
请求池
?
谢谢。
-
<<
答:我使用的是DI(EJB3.1),所以不需要在这里查找。(应用程序打包在ear中,其中包含两个模块(web模块和ejb),它非常适合我)。但我只能在托管类中使用它。
所以…
2.我可以用手动查胎面吗?----
是的
3.我可以使用扩展threadpoolexecutor的bean并调用另一个实现runnable的bean吗?还是不允许?