Is JAX-RS Client Thread Safe

前端 未结 2 1911
粉色の甜心
粉色の甜心 2021-02-05 04:07

In Java EE7, the JAX-RS Client API provides a high-level API for accessing any REST resources. According to the documentation, \"Clients are heavy-weight objects that manage

2条回答
  •  北海茫月
    2021-02-05 04:35

    I am not sure but I think this is a implementation-specific decision.

    I couldn't find in the JAX-RS 2.0 specification nor in the Javadoc anything granting that javax.ws.rs.client.Client is thread-safe. But in the Resteasy (an implementor of JAX-RS) documentation I found:

    One default decision made by HttpClient and adopted by Resteasy is the use of org.apache.http.impl.conn.SingleClientConnManager, which manages a single socket at any given time and which supports the use case in which one or more invocations are made serially from a single thread. For multithreaded applications, SingleClientConnManager may be replaced by org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager:

    ClientConnectionManager cm = new ThreadSafeClientConnManager();
    HttpClient httpClient = new DefaultHttpClient(cm);
    ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
    

    Source: http://docs.jboss.org/resteasy/docs/3.0.9.Final/userguide/html/RESTEasy_Client_Framework.html#transport_layer

    Based in these information I guess that the answer for your question is likely to be "no".

提交回复
热议问题