- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Call the run() method of the Timer Task in Java
The java.util.TimerTask.run() method looks onto the action to be performed by the task. It is used to carry out the action performed by the task.
Declaration −The java.util.TimerTask.run() method is declared as follows −
public abstract void run()
Let us see an example program to call the run() method of the Timer Task −
Example
import java.util.*; class MyTask extends TimerTask { public void run() { System.out.println("Running"); } } public class Example { public static void main(String[] args) { // creating timer task, timer TimerTask task = new MyTask(); Timer timer = new Timer(); // scheduling the task timer.scheduleAtFixedRate(task, new Date(), 3000); } }
Output
Running Running Running Running
- Related Articles
- Cancel the Timer Task in Java
- What will happen if we directly call the run() method in Java?
- Can we call run() method directly instead of start() in Java
- Remove all cancelled tasks from the timer's task queue in Java
- Terminate the timer in Java
- How can we call the invokeLater() method in Java?\n
- Can we call the wait() method without acquiring the lock in Java?
- Can we call methods of the superclass from a static method in java?
- How to run a timer in background within your iOS app
- Timer Class in Java
- Can we synchronize a run() method in Java?
- How to start the specific task of the task scheduler using PowerShell?
- How to call an interface method in Java?
- Java Program to get the current value of the system timer in nanoseconds
- How do we call a Java method recursively?

Advertisements