Is there a way to make something like a thread that does something every x amount of ms that I can start, stop, and resume when I want it to? I know that a thread can be started but there is no real safe way to stop and resume a thread.
Here are a bunch of examples on how to start/stop periodic tasks in Java:
The example from the first link:
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(yourRunnable, 8, 8, HOURS);
You can use the java.util.Timer class to schedule tasks on a background worker thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With