Announcement Announcement Module
No announcement yet.
JVM termination, daemon threads Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • JVM termination, daemon threads

    Day 1 of Spring Integration here...I've got a simple directory monitor working but the JVM doesn't exit when I interrupt the main thread with Control-C. I tried specifying daemon=false as described here but that had no effect.

    My configuration (with failed attempt at daemon=false) is as follows. What configuration do I need to make the JVM exit?

    	<int:channel id="fileChannel" datatype="">
    		<int:dispatcher task-executor="fileChannelTaskExecutor" />
    	<bean id="fileChannelTaskExecutor"
    		<property name="corePoolSize" value="2"/>
    		<property name="daemon" value="false"/>
    	<int:poller default="true" max-messages-per-poll="1"
    		fixed-rate="1000" />
    		directory="file:c:/watch" channel="fileChannel" prevent-duplicates="true" />
    	<int:outbound-channel-adapter channel="fileChannel" 
    		ref="target" method="handleMessage" >
    	<bean id="target" class="...

  • #2
    Can you attach a thread dump? (I think it's Ctrl-Break on Windows, but you can use jstack or VisualVM too).


    • #3
      I have no problems with CTRL-C ; but I am an using a JVM Shutdown and a Spring Context Listener Shutdown hook. The
      JVM Shutdown will tell Spring to close... The Spring Context listener will tell the Sched/Executor to passivate. Seems to work for me!

      class Main {
        private static ClassPathXmlApplicationContext springCtx;
        public static void main(String [] args) {
          // Create a global shutdown handler to take down the Spring Container
          Runtime.getRuntime().addShutdownHook(new Thread() {
                  public void run() {
                      if (springCtx != null) {
            "*** Started Spring shutdown...");
              // Bootstrap Spring Container
              springCtx = new ClassPathXmlApplicationContext(new String[]{
              // When the Spring Container is told to shutdown, add a Listener to terminate the Task Scheduler and its thread pool
              springCtx.addApplicationListener(new TaskSchedulerShutdownHandler());
             //  The rest of your main method goes here
        // Task Shutdown handler - uses static Spring Context to locate Task Scheduler and Executor and take it down easy.
      static class TaskSchedulerShutdownHandler implements ApplicationListener<ContextClosedEvent> {
              public void onApplicationEvent(ContextClosedEvent event) {
                  ThreadPoolTaskExecutor executor = springCtx.getBean(ThreadPoolTaskExecutor.class);
                  ThreadPoolTaskScheduler scheduler = springCtx.getBean(ThreadPoolTaskScheduler.class);
                  if (executor != null) {
                  if (scheduler != null) {
        "*** Shutdown Spring scheduler and executor...");


      • #4
        Originally posted by Gary Russell View Post
        Can you attach a thread dump? (I think it's Ctrl-Break on Windows, but you can use jstack or VisualVM too).
        Thanks for the push in the right direction; it turns out this had nothing to do with threads.
        I had been starting the windows cmd shell with Cygwin shell as parent process. Turns out
        I can't interrupt any Java process with a cmd shell started that way. If I start cmd shell
        the ordinary way, everything works fine.