Experimenting with the Timer, I just can not understand why main after three times outputting System.out.println("красный" + switcher); to the console System.out.println("красный" + switcher); does not end up ??? Here are 2 classes:
public class NACHALO { public static void main(String args[]) { Timer tr1 = new Timer(); forTimerTask task = new forTimerTask(tr1); tr1.schedule(task , 0, 1000); } } and
import java.util.Timer; import java.util.TimerTask; public class forTimerTask extends TimerTask{ Timer tTT = new Timer(); forTimerTask (Timer t){ tTT = t; } int switcher = 0; @Override public void run() { switcher++; System.out.println("красный" + switcher); if (switcher == 3){ tTT.cancel(); return; } } }