Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Java Timer class

[es] :: Java :: Java Timer class

[ Pregleda: 2542 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

sendai

Član broj: 98530
Poruke: 65
*.adsl-mo.bih.net.ba.



Profil

icon Java Timer class27.09.2007. u 02:16 - pre 200 meseci
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]
 
Odgovor na temu

anon315

Član broj: 315
Poruke: 1657
*.adsl-1.sezampro.yu.



+13 Profil

icon Re: Java Timer class27.09.2007. u 09:33 - pre 200 meseci
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
 
Odgovor na temu

[es] :: Java :: Java Timer class

[ Pregleda: 2542 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.