I am looking for something like the JavaScript setTimeout, but with a Runnable, with the following restrictions:
- Does not require individual dedicated threads per timeout.
- Already developed and thought through.
- Maybe even including additional features. (cancel timeout?, wait for something?, async I/O?)
- Does not require any GUI libraries. (Java FX/Swing/AWT all have event loops built in)
Do you have any suggestions?
Edit: I have found what I am looking for. A plus would be if there was a library that also included something related to either non-blocking or asynchronous I/O.
You’re probably looking for ScheduledThreadPoolExecutor :
I don’t really understand the link between scheduled runnables and an event loop, but maybe you’ll find what you’re looking with this class.