I have found a way out. These tags
@PostConstruct()
and
@PreDestroy()
Create 2 methods in your servlet that return void and accept no parameters.
place the 1st tag immediately above the first method and the 2nd tag above second tag.
Essense of the Tags
The @PostConstruct method is called by the container before the implementing class begins responding to web service clients.
The @PreDestroy method is called by the container before the endpoint is removed from operation.
inside the PostConstruction() method create your thread using the runnable interface and have it run in an infinite loop unless the value of a certain boolean variable is false.
use the PreDestroy() method to set the boolean variable to false.