I'm creating a web application with servlets and I need a thread changing a number constantly and when a client do a request it gets the current number.
I tried creating a class with the main method and from there start the thread, then from the servlet get the instance where the thread is running (can this be possible?), but the application never enters to the main method.
Any suggestions? Thanks
Servlets run in a web container and the web container's main method is out of your control.
If you want to perform any startup operations, then the servlet framework provides context listeners that can be registered with the framework. These listeners are called when your web application starts.
Alternatively, if you want to perform some operation on each incoming request or outgoing response, then you can use servlet filters