This example will show you how to run Running Infinite TimerTask in Java Servlet. For achieving this we can initialise TimerTask inside ServletContextListener and schedule it for a certain time period. ServletContextListener is used to, make your code run before your web application started. For more understanding on ServletContextListener, refer my post on ServletContextListener Example in Servlet.
This example explains how to use ServletContextListener in Servlets. ServletContextListener is used to, make your code run before your web application started. Below use case examples will help for more understanding.
Servlets are server side Java program which responds to network requests, mostly HTTP requests. Servlets are used to implement the dynamic web applications. Commonly servlets use various other frameworks like Struts, Hibernate, etc. which gives high level features for developing robust server application.