From: <ma...@rh...> - 2008-12-15 19:33:06
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } --></style> <title>[rhq-project.org rhq] [2401] wait for threads to die during shutdown</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>2401</dd> <dt>Author</dt> <dd>mazz</dd> <dt>Date</dt> <dd>2008-12-15 13:33:03 -0600 (Mon, 15 Dec 2008)</dd> </dl> <h3>Log Message</h3> <pre>wait for threads to die during shutdown</pre> <h3>Modified Paths</h3> <ul> <li><a href="#rhqtrunkmodulesenterpriseagentsrcmainjavaorgrhqenterpriseagentAgentShutdownHookjava">rhq/trunk/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentShutdownHook.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseagentsrcmainjavaorgrhqenterpriseagenti18nAgentI18NResourceKeysjava">rhq/trunk/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="rhqtrunkmodulesenterpriseagentsrcmainjavaorgrhqenterpriseagentAgentShutdownHookjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentShutdownHook.java (2400 => 2401)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentShutdownHook.java 2008-12-15 18:52:14 UTC (rev 2400) +++ rhq/trunk/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentShutdownHook.java 2008-12-15 19:33:03 UTC (rev 2401) </span><span class="lines">@@ -64,12 +64,9 @@ </span><span class="cx"> agent.shutdown(); // try to interrupt all non-daemon threads so they die faster; but only try a fixed number of times </span><span class="rem">- for (int i = 0; i < 5; i++) { - int threadsStillAlive = interruptAllNonDaemonThreads().size(); - if (threadsStillAlive == 0) { - break; - } - showMessage(AgentI18NResourceKeys.EXIT_SHUTDOWN_THREADS_LEFT, threadsStillAlive); </span><span class="add">+ int threadsStillAlive = waitForNonDaemonThreads(); + if (threadsStillAlive > 0) { + showMessage(AgentI18NResourceKeys.SHUTDOWNHOOK_THREADS_STILL_ALIVE, threadsStillAlive); </span><span class="cx"> } // set our timebomb to ensure the agent dies </span><span class="lines">@@ -86,15 +83,12 @@ </span><span class="cx"> } /** </span><span class="rem">- * Before we spawn our agent update binary, we want the current agent to be almost - * dead so this method will attept to wait for all other non-daemon threads to die - * before returning. </span><span class="add">+ * If you want the current agent to be dead this method will attept to wait for all + * other non-daemon threads to die before returning. </span><span class="cx"> * </span><span class="rem">- * We log messages if we can't wait for them all for whatever reason, but technically - * we can keep going since we don't necessarily have to have all threads to be dead. - * It just would be nice since we would then be assured the VM would die fast. </span><span class="add">+ * We log messages if we can't wait for them all for whatever reason. </span><span class="cx"> * </span><span class="rem">- * Note that obviously this method will not wait for the non-daemon update thread </span><span class="add">+ * Note that obviously this method will not wait for the calling thread </span><span class="cx"> * that is currently running this method. * * @return the number of still active non-daemon threads that haven't died even after waiting </span><span class="lines">@@ -106,7 +100,7 @@ </span><span class="cx"> while ((threadsStillActive > 0) && (countdown-- > 0)) { threadsStillActive = 0; List<Thread> threads = interruptAllNonDaemonThreads(); </span><span class="rem">- showMessage(AgentI18NResourceKeys.UPDATE_THREAD_WAIT, threads.size()); </span><span class="add">+ showMessage(AgentI18NResourceKeys.SHUTDOWNHOOK_THREAD_WAIT, threads.size()); </span><span class="cx"> for (Thread thread : threads) { try { thread.join(10000L); </span><span class="lines">@@ -119,11 +113,11 @@ </span><span class="cx"> } } if (threadsStillActive > 0) { </span><span class="rem">- showMessage(AgentI18NResourceKeys.UPDATE_THREAD_NO_MORE_WAIT, threadsStillActive); </span><span class="add">+ showMessage(AgentI18NResourceKeys.SHUTDOWNHOOK_THREAD_NO_MORE_WAIT, threadsStillActive); </span><span class="cx"> } return threadsStillActive; } catch (Throwable t) { </span><span class="rem">- showMessage(AgentI18NResourceKeys.UPDATE_THREAD_CANNOT_WAIT, ThrowableUtil.getAllMessages(t)); </span><span class="add">+ showMessage(AgentI18NResourceKeys.SHUTDOWNHOOK_THREAD_CANNOT_WAIT, ThrowableUtil.getAllMessages(t)); </span><span class="cx"> return Thread.activeCount(); } } </span></pre></div> <a id="rhqtrunkmodulesenterpriseagentsrcmainjavaorgrhqenterpriseagenti18nAgentI18NResourceKeysjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java (2400 => 2401)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java 2008-12-15 18:52:14 UTC (rev 2400) +++ rhq/trunk/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java 2008-12-15 19:33:03 UTC (rev 2401) </span><span class="lines">@@ -28,6 +28,10 @@ </span><span class="cx"> */ @I18NResourceBundle(baseName = "agent-messages", defaultLocale = "en") public interface AgentI18NResourceKeys { </span><span class="add">+ @I18NMessage("There are still [{0}] threads left - the kill thread will be started\\n\\\n" + + "and exit the VM in a few minutes if these threads have not died by then") + String SHUTDOWNHOOK_THREADS_STILL_ALIVE = "AgentShutdownHook.threads-still-alive"; + </span><span class="cx"> @I18NMessage("Missing the envvar [{0}] - will try to find a Java executable to use.") String UPDATE_THREAD_LOOKING_FOR_JAVA_EXE = "AgentUpdateThread.looking-for-java-exe"; </span><span class="lines">@@ -38,13 +42,13 @@ </span><span class="cx"> String UPDATE_THREAD_CANNOT_RESTART = "AgentUpdateThread.cannot-restart"; @I18NMessage("The agent will wait for [{0}] threads to die") </span><span class="rem">- String UPDATE_THREAD_WAIT = "AgentUpdateThread.wait"; </span><span class="add">+ String SHUTDOWNHOOK_THREAD_WAIT = "AgentShutdownHook.wait"; </span><span class="cx"> @I18NMessage("The agent failed waiting for threads to die: {0}") </span><span class="rem">- String UPDATE_THREAD_CANNOT_WAIT = "AgentUpdateThread.cannot-wait"; </span><span class="add">+ String SHUTDOWNHOOK_THREAD_CANNOT_WAIT = "AgentUpdateThread.cannot-wait"; </span><span class="cx"> @I18NMessage("[{0}] threads are not dying - agent will not wait anymore") </span><span class="rem">- String UPDATE_THREAD_NO_MORE_WAIT = "AgentUpdateThread.no-more-wait"; </span><span class="add">+ String SHUTDOWNHOOK_THREAD_NO_MORE_WAIT = "AgentShutdownHook.no-more-wait"; </span><span class="cx"> @I18NMessage("The agent update thread encountered an exception: {0}") String UPDATE_THREAD_EXCEPTION = "AgentUpdateThread.exception"; </span><span class="lines">@@ -691,13 +695,13 @@ </span><span class="cx"> String EXIT_HELP = "PromptCommand.exit.help"; @I18NMessage("Shutting down...") </span><span class="rem">- String EXIT_SHUTTING_DOWN = "PromptCommand.exit.shutting-down"; </span><span class="add">+ String EXIT_SHUTTING_DOWN = "AgentShutdownHook.exit.shutting-down"; </span><span class="cx"> @I18NMessage("Shutdown complete - agent will now exit.") </span><span class="rem">- String EXIT_SHUTDOWN_COMPLETE = "PromptCommand.exit.shutdown-complete"; </span><span class="add">+ String EXIT_SHUTDOWN_COMPLETE = "AgentShutdownHook.exit.shutdown-complete"; </span><span class="cx"> @I18NMessage("An error occurred during shutdown. Cause: {0}") </span><span class="rem">- String EXIT_SHUTDOWN_ERROR = "PromptCommand.exit.shutdown-error"; </span><span class="add">+ String EXIT_SHUTDOWN_ERROR = "AgentShutdownHook.exit.shutdown-error"; </span><span class="cx"> @I18NMessage("debug") String DEBUG = "PromptCommand.debug"; </span> </pre> </div> </div> </body> </html> |