Background thread creation in Weblogic SOAP Webservice using Executor framework

∥☆過路亽.° 提交于 2020-01-04 05:35:28

问题


We have a SOAP webservice deployed on Weblogic server with the flow as follows.

SOAP Client will send message to Webservice which validates the message and sends an Acknowledgement as response of the service. However, it is suppose to do a SocketConnection in the background to further process the message as asynchronously.

The implementation that has been provided is to spawn a ChildThread in the background using ExecutorService.newFixedThreadPool. this is the code being used (not all the code for the webservice implementation file is posted here).

  if ("103".equals(requestType)) {
    ExecutorService executorService = Executors.newFixedThreadPool(1);
    executorService.submit(new MessageProcessing103(coreMsg, otherDetails));
  } else if ("104".requestType) {
         ExecutorService executorService = Executors.newFixedThreadPool(1);
         executorService.submit(new MessageProcessing104(coreMsg, otherDetails));
    }

With the above implementation Scalability is definitely an issue but we can live with it as of now. Can you help with the below queries though

  1. Since background thread is long living does that mean the same spawned thread will be used to execute all the requests?
  2. If two requests come in at an interval of within few seconds, will the second request be in waiting state or new thread will be spawned?
  3. We are not shutting down the executor so what would be the issues encountered in such a case?

回答1:


  1. For each request, you create a new thread which executes only that request.
  2. Same.
  3. Very soon you encounter an OutOfMemoryError - created and not shutted executors eat all the memory.

My advice is not to create new executor for each request, but reuse the same executor. And let that executor contain several threads. not one.




回答2:


This is the approach I devised for the above problem.

Can someone please validate and confirm if this can still cause any Out of Memory or threading issues.

Firstly, create a ThreadPool to serve average parallel threads.

public static final ExecutorService executorService = Executors.newFixedThreadPool(3);

Next, invoke the respective MessageProcessor Instances for the message type 103 or 104

  if ("103".equals(requestType)) {
       executorService.submit(new MessageProcessing103(coreMsg, otherDetails));
  } else if ("104".requestType) {
       executorService.submit(new MessageProcessing104(coreMsg, otherDetails));
    }

Finally, do the shutdown of the executorService if the Webservice Context destroys. For this will configure a listener in web.xml.

 <listener>
<listener-class>com.saurav.listener.AppContextListener</listener-class></listener>

Code inside AppContextListener --> contextDestroyed() function

ImplClass.executorService.shutdown();

In case of any exception will handle the same and do a shutdownNow()



来源:https://stackoverflow.com/questions/33260246/background-thread-creation-in-weblogic-soap-webservice-using-executor-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!