Let's create a timed process with Java Timer! !!

JavaTimer Can be used when you want to specify a time at regular intervals and execute processing

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() {
                //Processing that you want to execute on a regular basis
                count++;
                System.out.println(count + "It's the second task.");
            }
        };
        //After 2 seconds, run every 5 seconds
        timer.scheduleAtFixedRate(tt,2000,5000); 
    }
//timer.cancel();If you don't write, the process will work all the time, so be careful!
}

Recommended Posts

Let's create a timed process with Java Timer! !!
Let's create a Java development environment (updating)
Create a CSR with extended information in Java
Create a simple bulletin board with Java + MySQL
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
[Java] Create a filter
[Java] Create a collection with only one element
Let's create a super-simple web framework in Java
[Java] Let's create a mod for Minecraft 1.14.4 [Introduction]
[Java] Let's create a mod for Minecraft 1.16.1 [Introduction]
Let's scrape with Java! !!
[Java] Let's create a mod for Minecraft 1.14.4 [99. Mod output]
Let's go with Watson Assistant (formerly Conversation) ⑤ Create a chatbot with Watson + Java + Slack
Let's make a calculator application with Java ~ Create a display area in the window
[Java] Let's create a mod for Minecraft 1.14.4 [0. Basic file]
[Java] Let's create a mod for Minecraft 1.14.4 [4. Add tools]
[Java] Let's create a mod for Minecraft 1.14.4 [5. Add armor]
[Java] Let's create a mod for Minecraft 1.14.4 [Extra edition]
[Java] Let's create a mod for Minecraft 1.14.4 [7. Add progress]
[Java] Let's create a mod for Minecraft 1.14.4 [6. Add recipe]
[Beginner] Create a competitive game with basic Java knowledge
[Java] Let's create a mod for Minecraft 1.16.1 [Add item]
[Java] Let's create a mod for Minecraft 1.16.1 [Basic file]
[Java basics] Let's make a triangle with a for statement
[Java] Let's create a mod for Minecraft 1.14.4 [1. Add items]
[Note] Create a java environment from scratch with docker
[Java] Let's create a mod for Minecraft 1.14.4 [2. Add block]
[Java] Let's create a mod for Minecraft 1.16.1 [Add block]
Let's experiment with Java inlining
Let's operate Excel with Java! !!
Create a java method [Memo] [java11]
[Java] Create a temporary file
Create a playground with Xcode 12
Let's create a TODO application in Java 11 Exception handling when accessing TODO with a non-existent ID
I tried to create a java8 development environment with Chocolatey
[Java] Let's create a mod for Minecraft 1.14.4 [3. Add creative tab]
Create a SlackBot with AWS lambda & API Gateway in Java
[Java] Let's replace data objects with a mapper ~ BeanMapper Orika ~
Study Java: Use Timer to create something like a bomb timer
Create a simple DRUD application with Java + SpringBoot + Gradle + thymeleaf (1)
Create an immutable class with JAVA
Create a Vue3 environment with Docker!
Build a Java project with Gradle
Let's create Ubuntu environment with vmware
Creating a timer app with a muddy
Create a Java project using Eclipse
[Java] How to create a folder
Create exceptions with a fluid interface
Create a Maven project with a command
Create a simple web server with the Java standard library com.sun.net.httpserver
Let's create a TODO application in Java 4 Implementation of posting function
I can't create a Java class with a specific name in IntelliJ
Let's create a TODO application in Java 6 Implementation of search function
Create a high-performance enum with fields and methods like Java with JavaScript
Let's create a TODO application in Java 8 Implementation of editing function
[Java] Let's create a mod for Minecraft 1.16.1 [Add and generate trees]
[Java] Let's create a mod for Minecraft 1.14.4 [9. Add and generate trees]
Let's create a TODO application in Java 1 Brief explanation of MVC
Let's create a TODO application in Java 5 Switch the display of TODO
[Java] Let's create a mod for Minecraft 1.14.4 [8. Add and generate ore]
Let's create a parameter polymorphic mechanism with Generic Dao and Hibernate