运行CXF JAX-RS 2.0客户端“目标"时出现NullPointerException.线程下的Liberty Profile中的方法 [英] NullPointerException when running CXF JAX-RS 2.0 client "target" method in Liberty Profile under a Thread
问题描述
我在Liberty Profile 8.5.5.6中有一些运行正常的JAX-RS 2.0客户端.它们都可以按顺序正常工作,但是我想在一个线程中执行其中的一些,以便它们同时运行.当我尝试通过以下方式在FutureTask中获取目标"时:
I have some JAX-RS 2.0 clients running ok in Liberty Profile 8.5.5.6. They are all working ok sequentially, but I want to execute some of them in a Thread so they run concurrently. When I try to get a "target" inside a FutureTask with:
WebTarget myResource = client.target(apiURLBase + ...);
在此com.ibm.ws ...类中,我得到了NullPointerExcepton:
I get NullPointerExcepton in this com.ibm.ws... class:
Caused by: java.lang.NullPointerException
at com.ibm.ws.jaxrs20.client.bus.LibertyJAXRSClientBusFactory.getClientScopeBus(LibertyJAXRSClientBusFactory.java:89)
at com.ibm.ws.jaxrs20.client.JAXRSClientImpl.target(JAXRSClientImpl.java:109)
at org.apache.cxf.jaxrs.client.spec.ClientImpl.target(ClientImpl.java:100)
at com.servengine.watson.naturallanguageclassifier.NaturalLanguageClassifierRESTClient.classify(NaturalLanguageClassifierRESTClient.java:161)
at com.servengine.watson.naturallanguageclassifier.NaturalLanguageClassifierRESTClient$Proxy$_$$_WeldClientProxy.classify(Unknown Source)
at com.skios.eliza.nlq.NaturalLanguageQueryFlowView$1.call(NaturalLanguageQueryFlowView.java:66)
at com.skios.eliza.nlq.NaturalLanguageQueryFlowView$1.call(NaturalLanguageQueryFlowView.java:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
不能在主"线程中使用CXF吗?我想念什么?
CXF cannot be used out of "main" Thread? What am I missing?
感谢您的帮助.
推荐答案
如果要在派生的新线程中使用客户端API,则需要确保新线程是容器托管的.您可以启用并发1.0功能.然后使用:
If you want to use the client API in a forked new thread, you need to make sure the new thread is a container managed one. In your case, you can enable concurrent-1.0 feature. Then use:
@Resource(name ="java:comp/DefaultManagedExecutorServcie") ManagedExecutorService执行程序;
@Resource(name="java:comp/DefaultManagedExecutorServcie") ManagedExecutorService executor;
Task task = new Task();
Future<String> result = executor.submit(task);
在您的Task类中,您可以做与以前相同的事情:WebTarget myResource = client.target(apiURLBase + ...);
In Your Task class, you can do the same thing with what you done before: WebTarget myResource = client.target(apiURLBase + ...);
这篇关于运行CXF JAX-RS 2.0客户端“目标"时出现NullPointerException.线程下的Liberty Profile中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!