Help us understand the problem. What is going on with this article?

JavaのTimerで時間指定の処理を作ろう!!

JavaTimer

一定間隔の時間を指定して、処理を実行したいときに使える

JavaTimer
import java.util.Timer;
import java.util.TimerTask;

public class TimeAction {

    public static void main(String[] args) {

        Timer timer = new Timer(); 
        TimerTask tt = new TimerTask() {
            int count = 0;
            public void run() {
                // 定期的に実行したい処理
                count++;
                System.out.println(count + "回目のタスクだよん。");
            }
        };
        //2秒後に、5秒間隔で実行する
        timer.scheduleAtFixedRate(tt,2000,5000); 
    }
//timer.cancel();を書かないとずっと処理が動くので気をつけましょう!
}
spacecow
現在iOSとAndroid開発をしているプログラマです:) まえはWebと組み込みもやてました!
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした