javax.management.timer


1. Creating a Timer

import javax.management.timer.Timer;

public class CreateTimer {

    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.setName("My Timer");
    }
}

2. Scheduling a One-Time Timer Task

import javax.management.timer.Timer;
import javax.management.timer.TimerListener;

public class ScheduleOneTimeTask {

    public static void main(String[] args) {
        Timer timer = new Timer();
        TimerListener listener = new TimerListener() {
            @Override
            public void timerElapsed(TimerEvent event) {
                System.out.println("Timer task completed.");
            }
        };
        timer.schedule(listener, 5000); // Schedule the task to run in 5 seconds
    }
}

3. Scheduling a Periodic Timer Task

4. Scheduling a Fixed-Delay Timer Task

5. Canceling a Timer Task

6. Getting the Timer's Queue

7. Getting the Timer's Properties

8. Setting the Timer's Properties

9. Starting the Timer

10. Stopping the Timer

11. Purging the Timer's Queue

12. Creating a Timer Factory

13. Getting the Default Timer Factory

14. Getting the Timer Factory's Attributes

15. Getting the Timer Factory's Features

16. Scheduling a Timer Task with a Start Time

17. Scheduling a Timer Task with a Period and Start Time

18. Scheduling a Timer Task with a Fixed Delay and Start Time