0
我們有運行一些線程的代碼。在線程的運行事件中,我們調用2個Web服務。當達到迭代次數2000時,我們遇到了性能問題。每個Web服務調用的進程運行時間爲600毫秒,並且隨着它繼續,它可能會接近60秒...Java多線程變得更慢
每個Web服務的實際執行保持一致,但端口創建變慢:
long preStartTime = System.currentTimeMillis();
ServicePortType winPort = (ServicePortType) this.getConnector().getFactory().create();
long preEndTime = System.currentTimeMillis();
LOGGER.debug("@@@Web Service Prep work (1st service) took => " + (preEndTime - preStartTime) + "ms");
這將記錄在開始大約80毫秒,隨着工藝的不斷運行,它可以上升到50秒的時候在2000年迭代:
(iteration 1) @@@Web Service Prep work (1st service) took => 80ms
(iteration 2000) @@@Web Service Prep work (1st service) took => 524421ms
這是connec tor設置:
@Override
public void init(Properties prop) {
LOGGER.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
LOGGER.info("@@@@@@ Starting HTTPConnector @@@@@@@@@@@@@@");
LOGGER.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
try {
factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(ServicePortType.class);
LOGGER.debug("@@@URL : " + prop.getProperty("service.url"));
factory.setAddress(prop.getProperty("service.url"));
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
} catch (Exception ex) {
LOGGER.error(ex);
}
LOGGER.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
LOGGER.info("@@@@@@ End HTTPConnector @@@@@@@@@@@@@@@@@@@");
LOGGER.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
}
任何人都可以在這裏指導我嗎?
編輯
我改變了這一部分這是所謂的每一次靜態和它只會創建一次。現在表現很好,但不知道這是否會影響其他方面。
從這:
ServicePortType winPort = (ServicePortType) this.getConnector().getFactory().create();
要這樣:
private static UVSInterfaceExtendPortType winPort;
if (winPort == null)
{
winPort = (UVSInterfaceExtendPortType) this.getConnector().getFactory().create();
}
你可以在Factory類的create()中發佈代碼嗎? –
@sunrise:它是JaxWsProxyFactoryBean.java(編譯後的代碼)的一部分。我現在正在測試的只是在構造函數中初始化端口。似乎工作得更好。儘管如此仍在監控 –
你應該正式知道,JAX-WS代理類[不是線程安全的](http://stackoverflow.com/questions/4385204/are-jax-ws-clients-thread-safe)。通過使用JaxWsProxyFactoryBean,我會假設你正在運行CXF,在這種情況下,答案仍然是[*有時*](http://cxf.apache.org/faq.html#FAQ-AreJAXWSclientproxiesthreadsafe%3F )。根據您的設置,您到達的「解決方案」可能會導致您在其他地方出現問題。在生產系統中,更多的線程實際上並不意味着更好的性能,它實際上可能意味着*更少的性能。您擁有的線程越多,... – kolossus