[ sendai @ 27.09.2007. 02:16 ] @
Imam jedno pitanje u vezi Timer klase.Prvo jedan jednostavam kod:

Code:
 import java.util.*;

 public class Tm {
        public static void main(String[] args) throws Exception {

   System.out.println("##############");
    Timer timer = new Timer();

      timer.schedule(new TimerTask(){
            public void run() {                
          for(int i = 0; i < 10; i++)
                System.out.print(" " + i); }}, 2000);

     timer.schedule(new TimerTask(){
            public void run() {                
          for(int i = 0; i < 10; i++)
                System.out.print(" " + i); }}, 5000);

   System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
        }
       }

Dakle ono sto mi se dogadja je da program ne moze da se zavrsi, prvo ispise
############### i
$$$$$$$$$$$$$$$$$$$$$$$
sto je i u redu, pa onda prvu petlju i drugu i stane i ne zavrsi se.
U cemu grijesim?
PS.
Znam da mogu da postavim timer kao daemon thread, ali zasto ovako ne radi?


[Ovu poruku je menjao sendai dana 27.09.2007. u 03:28 GMT+1]
[ anon315 @ 27.09.2007. 09:33 ] @
Citat:

After the last live reference to a Timer object goes away and all outstanding tasks have completed execution, the timer's task execution thread terminates gracefully (and becomes subject to garbage collection). However, this can take arbitrarily long to occur. By default, the task execution thread does not run as a daemon thread, so it is capable of keeping an application from terminating. If a caller wants to terminate a timer's task execution thread rapidly, the caller should invoke the timer's cancel method.


http://java.sun.com/j2se/1.5.0/docs/api/java/util/Timer.html