I have a small Java Websocket Servlet running on Tomcat 8.0.5. Usually, it answers every received message immediately. But in some use case, it would be nice to have a scheduled event, that runs exactly once after some delay and sends new messages to clients. I've already done some research, but I am not sure whether those articles fit my requirements:
How to run a background task in a servlet based web application?
How to schedule a task in Tomcat
My approach to solve this would be some kind of a Service, that takes an integer for the delay and some other required parameters. Based on that it creates a new Thread that will send some new messages after doing Thread.sleep(integer).
Is that an appropriate solution or is there some 'best practice' to solve this?