我们在Weblogic服务器上部署了一个SOAP We服务,流程如下所示。
SOAP客户端将向Webservice发送消息,Webservice验证消息并将确认作为服务的响应发送。但是,应该在后台执行一个SocketConnection,以进一步异步地处理消息。
提供的实现是在后台使用ChildThread生成一个ExecutorService.newFixedThreadPool。这是正在使用的代码(并不是webservice实现文件的所有代码都在这里发布)。
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));
}有了上面的实现,可伸缩性肯定是个问题,但到目前为止,我们可以接受它。不过,你能帮我做以下的查询吗?
发布于 2015-10-21 15:39:28
我的建议不是为每个请求创建新的执行器,而是重用相同的执行器。让执行者包含几个线程。一个都没有。
发布于 2015-10-22 05:04:47
这就是我为上述问题设计的方法。
请有人验证并确认这是否仍会导致内存不足或线程问题。
首先,创建一个ThreadPool来服务于平均并行线程。
public static final ExecutorService executorService = Executors.newFixedThreadPool(3);接下来,为消息类型103或104调用相应的MessageProcessor实例。
if ("103".equals(requestType)) {
executorService.submit(new MessageProcessing103(coreMsg, otherDetails));
} else if ("104".requestType) {
executorService.submit(new MessageProcessing104(coreMsg, otherDetails));
}最后,如果Webservice上下文破坏,请关闭executorService。为此,将在web.xml中配置侦听器。
<listener>
<listener-class>com.saurav.listener.AppContextListener</listener-class></listener>AppContextListener --> contextDestroyed()函数中的代码
ImplClass.executorService.shutdown();如果出现任何异常,将处理相同的事件并执行shutdownNow()
https://stackoverflow.com/questions/33260246
复制相似问题