Java.util.Timer - how can I run it now (before its actual schedule)

I have java.util.Timer in my application that fires at a certain point. But certain events may occur that require events triggered by this timer to occur.

Is it possible to make the timer be early, so to speak?

+4
source share
2 answers

Your requirements sound mutually exclusive. Things happen on a schedule or as random events, but not both.

This is similar to what you want for those events that do not fit into the scheduler, which will be broadcast to the listener, which the Contractor can cancel to process them asynchronously.

+2
source

A TimerTask is Runnable , so you can execute it directly in a new thread.

What you can do to run immediately:

I'm not going to say that this is a good design choice, though.

+1
source

Source: https://habr.com/ru/post/1385102/


All Articles