如何使用jax rs同步后方法响应

时间:2019-10-16 07:55:54

标签: jax-rs

我编写了Web服务,用于从支付网关读取json格式的响应,并将该响应发送到DB。在这里,我面临着如何使用JAX-RS同步付款响应的问题。

Path("/userService")
@POST
@Consumes(MediaType.APPLICATION_JSON)

public synchronized void getUserDetails(InputStream incomingData,@Suspended final AsyncResponse asyncResponse) throws JSONException {

    StringBuilder crunchifyBuilder = new StringBuilder();
    try {
            BufferedReader in = new BufferedReader(new  InputStreamReader(incomingData));
            String line = null;
            while ((line = in.readLine()) != null) {
                crunchifyBuilder.append(line);
        }
        } catch (Exception e) {
            System.out.println("Error Parsing: - ");
        }

           new Thread(new Runnable() {  

    public void  run() {        
        PostingAckresponse1=sendDataToDB(crunchifyBuilder);
                        asyncResponse.resume(response);

                }
             }.start();

}

0 个答案:

没有答案