开发学院软件开发Java CXF client在并发下的线程安全问题 阅读

CXF client在并发下的线程安全问题

 2009-09-24 00:00:00 来源:WEB开发网   
核心提示: 修改后的客户端代码在之后的测试中,非常稳定,没有再出现上面的异常,CXF client在并发下的线程安全问题(4),问题算是解决了,我对cxf不是很熟悉,找了一下也没有找到到底是那里造成的线程不安全,google了一下找到几个地方

修改后的客户端代码在之后的测试中,非常稳定,没有再出现上面的异常,问题算是解决了。

我对cxf不是很熟悉,找了一下也没有找到到底是那里造成的线程不安全,google了一下找到几个地方,但是似乎还不能完全说明问题。先列出来慢慢研究:

1) Are JAX-WS client proxies thread safe?

装载自这里:http://cxf.apache.org/faq.html#FAQ-AreJAXWSclientproxiesthreadsafe%253F

Official JAX-WS answer: No. According to the JAX-WS spec, the client proxies are NOT thread safe. To write portable code, you should treat them as non-thread safe and synchronize access or use a pool of instances or similar.

CXF answer: CXF proxies are thread safe for MANY use cases. The exceptions are:

* Use of ((BindingProvider)proxy).getRequestContext() - per JAX-WS spec, the request context is PER INSTANCE. Thus, anything set there will affect requests on other threads. With CXF, you can do:

((BindingProvider)proxy).getRequestContext().put("thread.local.request.context", "true");

((BindingProvider)proxy).getRequestContext().put("thread.local.request.context", "true");

and future calls to getRequestContext() will use a thread local request context. That allows the request context to be threadsafe. (Note: the response context is always thread local in CXF)

* Settings on the conduit - if you use code or configuration to directly manipulate the conduit (like to set TLS settings or similar), those are not thread safe. The conduit is per-instance and thus those settings would be shared.

上一页  1 2 3 4 5  下一页

Tags:CXF client 并发

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接