The webapp backend is deployed in the Tomcat 6 servlet container. Several web threads are launched in webapp. The problem is disconnecting.
My thread is currently implemented as shown below. When a servlet is instructed to shut down (shutdown.sh), it completes a clean shutdown and does not freeze due to this thread. Why?
class Updater extends Thread { volatile boolean interrupted = false; @Override public void run() { Integer lastUpdateLogId = CommonBeanFactory.getXXX() .getLastUpdateLogRecordKey(MLConstants.SMART_DB_NAME); List<UpdateLog> updateLogRecords; while (!interrupted) { boolean isConfigurationUpdateRequested = false; try { TimeUnit.SECONDS.sleep(5); } catch (InterruptedException e) { setInterrupted(true); } updateLogRecords = CommonBeanFactory.getXXX() .getLastFactsUpdateLogRecords(MLConstants.XXXX, lastUpdateLogId); for(UpdateLog updateLog : updateLogRecords) { if (updateLog.getTable_name().equals(MLConstants.CONFIG_RELOAD)) { isConfigurationUpdateRequested = true; } lastUpdateLogId = updateLog.getObjectKey(); } if (isConfigurationUpdateRequested) { Configuration.getInstance().loadConfiguration(); } } } public boolean getInterrupted() { return interrupted; } public void setInterrupted(boolean interrupted) { this.interrupted = interrupted; } }
. , . , , init(). , destroy().
init()
destroy()
destroy() .
shutdown.sh, JVM . JVM , ( ) , . System.exit(0);
shutdown.sh
System.exit(0);
, . .
, , webapp ; , . *. , , - . .
Ctrl + C Tomcat ( Windows) , init script, Tomcat, . , , ...
: . ServletContextListener, "", . , , Thread.interrupt() contextDestroyed(). , destroy().
, , JVM . {sh | bat}. , script Tomcat. , .