K
K
Kirill Zhilyaev2020-02-21 01:13:06
Java
Kirill Zhilyaev, 2020-02-21 01:13:06

Is there a synchronous analogue of Timer?

There is an Update( ) method
which contains a series of checks of the form

if ( System.currentTimeMillis() - old_run_1  >= 1000 )
{
    // Что-то
}


Java has a Timer class that allows you to schedule jobs. But it runs in a separate thread.

Is there such a class that would accept tasks similar to Timer, but perform interval checks and execute tasks in the thread that called, roughly speaking, the checkAndRun () method?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-02-21
@sergey-gornostaev

A timer without a thread is a normal loop with checking the current time and sleeping on each iteration.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question