Proper way to make java.util.Timer a daemon
<p>I have the following <code>java.util.Timer</code> but it does not seem to execute and I don't know why.</p>

<pre><code>public static void main(String[] args)
{
  Timer to = new Timer(true);

  System.out.println("Now=" + System.currentTimeMillis());
  to.schedule(new TimeOutTask("Short#1 - 250"), 250);
  to.schedule(new TimeOutTask("Long - 10050"), 10050);
  to.schedule(new TimeOutTask("Short#2 - 250"), 250);
  to.schedule(new TimeOutTask("Medium - 5050"), 5050);
  to.schedule(new TimeOutTask("Short#3 - 250"), 250);
}
</code></pre>

<p>All the <code>TimeOutTask</code> does is print the passed string and the current time.  When the daemon flag is false the application does not terminate and I see this:</p>

<pre><code>Now=1297705592543
Short#1 - 250:1297705592793
Short#3 - 250:1297705592793
Short#2 - 250:1297705592793
Medium - 5050:1297705597605
Long - 10050:1297705602605
</code></pre>

<p>When true the application terminates and I see this:</p>

<pre><code>Now=1297705249422
</code></pre>

<p>I am just trying to find a way to monitor several tasks for time out purposes; I do not want the thread that monitors the time outs to keep the application from terminating.  So I want daemon but when I make it a daemon none of my tasks seem to execute?!?!</p>

<p>EDIT:</p>

<p>Interesting, I think my problem stems from the way I try out new ideas in isolation.  If I had a real app running it would keep the daemon thread alive and since these threads only represent time outs I don't care if they are done when the main app is finished.</p>

<p>I added this code to the end of my main method to pop up a frame and tested by closing it at different times.  If I wait long enough all my threads execute, if I don't then the application terminates gracefully even though some tasks have not executed.</p>

<pre><code>JFrame f = new JFrame("Test Frame");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setVisible(true);
</code></pre>

<p>Thanks for all your help.</p>
