title: How Keep JVM Alive Until All Threads Are Completed?
body: <p>I have a tool running, and is invoked through a BAT file in Command Prompt. In the tool, the Quartz scheduler periodically invokes a method, which performs the logic.</p>
  
  <p>As per current implementation, all this is done through a single thread, thus even if the CTRL+C is performed on the BAT file, the tool is not shutdown until the process completes.</p>
  
  <p>But, after looking at the process, we came up with the idea of performing part of the process in a separate thread. Here, the main thread would create a new thread, which would go on to perform some time consuming operations, while the parent thread dies. And another flow might be started by the Quartz even before the child thread has ended.</p>
  
  <p>Thus, at a time, there can be only one parent thread, which the Quartz creates, but there can be any number of child threads operating.</p>
  
  <p>In the above scenario, if CTRL+C is performed, then the Quartz scheduler only waits for the parent thread to complete before shutting down, and all other threads are left incomplete.</p>
  
  <p>I would really appreciate it if someone can tell me how can keep the tool running until all threads have completed.</p>
  
  <p>Thanks in advance.</p>
  
  <p>PS: I have tried attaching the newly created child threads as shutdown hooks, but it doesn't seem to solve my problem. Maybe I am doing it wrong, but it hasn't helped me as of yet.</p>