#ff0000 30  2005 . - #000655  
#def      -  (    )    . J2ME  ,    .    .     ,    : java.util.TimerTask    java.util.Timer.  TimerTask  ,          .  Timer     ,     .
        TimerTask   run():

---
import java.util.*;

public class MyTask extends TimerTask {
    public void run() {
        System.out.println( " " );
    }
}
---
          .
 TimerTask  java.lang.Runnable .        Timer.       ,         ,            .
 ,   ,     .       schedule()    Timer.
---
import java.util.*;

Timer     timer = new Timer();
TimerTask task = new MyTask();

//   ,    task()...
timer.schedule( task, 10000 );

//      task, 
//     10 
timer.schedule( task, 5000, 10000 );
---
     :       (  Date),    ( ),    ,          (    scheduleAtFixedRate)   ,      ( -  ),            ,         .
  Timer       .      ,       .        ,   cancel().   ,        -         . Timer   ,  ,             .
        ( run()).   cancel()  run() ,      .     cancel()    .    ,        ".         API.
---
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;

public class TimerDemo extends MIDlet {

    Display    display;
    StarField  field = new StarField();
    FieldMover mover = new FieldMover();
    Timer      timer = new Timer();

    public TimerDemo() {
        display = Display.getDisplay( this );
    }

    protected void destroyApp( boolean unconditional ) {
    }

    protected void startApp() {
        display.setCurrent( field );
        timer.schedule( mover, 100, 100 );
    }

    protected void pauseApp() {
    }

    public void exit(){
        timer.cancel(); //  
        destroyApp( true );
        notifyDestroyed();
    }

    class FieldMover extends TimerTask {
        public void run(){
            field.scroll();
        }
    }

    class StarField extends Canvas {
        int        height;
        int        width;
        int[]      stars;
        Random     generator = new Random();
        boolean    painting = false;

        public StarField(){
            height      = getHeight();
            width       = getWidth();
            stars       = new int[ height ];

            for( int i = 0; i < height; ++i ){
                stars[i] = -1;
            }
        }

        public void scroll() {
            if( painting ) return;

            for( int i = height-1; i > 0; --i ){
                stars[i] = stars[i-1];
            }

            stars[0] = ( generator.nextInt() %
                                ( 3 * width ) ) / 2;
            if( stars[0] >= width ){
                stars[0] = -1;
            }

            repaint();
        }

        protected void paint( Graphics g ){
            painting = true;

            g.setColor( 0, 0, 0 );
            g.fillRect( 0, 0, width, height );

            g.setColor( 255, 255, 255 );

            for( int y = 0; y < height; ++y ){
                int x = stars[y];
                if( x == -1 ) continue;

                g.drawline( x, y, x, y );
            }

            painting = false;
        }

        protected void keypressed( int keycode ){
            exit();
        }
    }
}

---

 MIDlet   Timer.  FieldMover   100 .      ,       .     .