簡體   English   中英

啟動了一個名為MultiThreadedHttpConnectionManager清理的線程,但未能將其停止

[英]Started a thread named MultiThreadedHttpConnectionManager cleanup but has failed to stop it

我正在使用Amazon Web Services AWS Java SDK編寫Web應用程序。 在后台使用Apache Commons HttpClient版本3。 我有commons-httpclient-3.0.1.jar。

我的catalina.out中有以下警告

SEVERE: The web application [/MyAppName] appears to have started a thread named
[MultiThreadedHttpConnectionManager cleanup] but has failed to stop it. This is 
very likely to create a memory leak.

所以我寫了一個帶有contextDestroyed()方法的ServletContextListener:

MultiThreadedHttpConnectionManager.shutdownAll();

但是,盡管調用了該方法,警告仍然顯示。 我還應該做什么以確保清理?

編輯 :我想絕對確定確實調用了contextDestroyed()(建議否),因此我在方法的第一條語句上放置了一個斷點,停止了服務器,並且斷點被擊中,我逐步執行了該方法確保不會引發異常,並且方法的每一行都沒有問題。 這是我的源代碼:

@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
    System.out.println("contextDestroyed() start");
    MyMemCache.shutDown();
    MultiThreadedHttpConnectionManager.shutdownAll();
    ClassLoader contextClassLoader=Thread.currentThread().getContextClassLoader();
    LogFactory.release(contextClassLoader);
    java.beans.Introspector.flushCaches();
    System.out.println("contextDestroyed() end");
}

熱插拔時:

INFO: Reloading Context with name [/MyAppName] has started
contextDestroyed() start
contextDestroyed() end
05 24, 11 3:11:00 PM org.apache.catalina.loader.WebappClassLoader 
    clearReferencesThreads
SEVERE: The web application [/MyAppName] appears to have started a thread 
    named [MultiThreadedHttpConnectionManager cleanup] but has failed to 
    stop it. This is very likely to create a memory leak.

這是AWS SDK中的一個錯誤,在該錯誤中,他們打開兩個HttpClient,而僅關閉其中一個。 我的問題略有不同,因為我想啟動和停止各個區域和帳戶的客戶端,而無需重新啟動Webapp。

我已經解決了這個問題(我已經向他們報告過,但他們似乎不願意解決):

public class MyAmazonEC2Client extends AmazonEC2AsyncClient {
    private boolean shutdownCalled = false;


    public MyAmazonEC2Client(final AWSCredentials awsCredentials) {
        super(awsCredentials);
    }


    public MyAmazonEC2Client(final AWSCredentials awsCredentials, final ClientConfiguration clientConfiguration) {
        this(awsCredentials, clientConfiguration, Executors.newCachedThreadPool());
    }


    public MyAmazonEC2Client(
                                 final AWSCredentials awsCredentials,
                                 final ClientConfiguration clientConfiguration,
                                 final ExecutorService executor) {
        super(awsCredentials, clientConfiguration, executor);
    }


    /**
     * Shuts down this client object, releasing any resources that might be held open.<br />
     */
    @Override
    public synchronized void shutdown() {
        try {
            shutdownCalled = true;

            // Call the proper shutdown method. This is in the base type and only shuts down one of the HttpClients created (the one that's never used)
            super.shutdown(); // close the HttpClient in AmazonWebServiceClient
        }
        finally {
            // Fix a bug in Amazon's implementation where they've duplicated the HttpClients
            try {
                super.client.shutdown(); // close the HttpClient in AmazonEC2Client
            }
            catch (Throwable t) {
                // ignore failures
            }
        }
    }
}

更新到AWS Java SDK版本1.2.1解決了該問題。 自我於2011年5月26日發布此問題以來,尚無此版本。

AWS開發工具包1.2。*使用2009年發布的HttpClient 4,但AWS Java開發工具包仍在其1.1。*版本中使用版本3。 自從我的問題解決以來,我將不進一步分析它們的代碼更改。

我在axis2 Web服務中也遇到了類似的錯誤,發現這是axis2 1.6版本中已修復的axis 錯誤

盡管對於AWS可以回答此問題,但我已將答案提交給正在尋找axis2類似錯誤的人員。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM