How to run JSP code every 15mins once without running it. I want to execute a jsp program code periodically every 15mins once.
            Asked
            
        
        
            Active
            
        
            Viewed 779 times
        
    2 Answers
2
            
            
        Java code doesn't belong in a JSP file. Just move that code into a real Java class. This way you can use ScheduledExecutorService in a ServletContextListener to execute it periodically. 
@WebListener
public class Config implements ServletContextListener {
    private ScheduledExecutorService scheduler;
    @Override
    public void contextInitialized(ServletContextEvent event) {
        scheduler = Executors.newSingleThreadScheduledExecutor();
        scheduler.scheduleAtFixedRate(new Task(), 0, 15, TimeUnit.MINUTES);
    }
    @Override
    public void contextDestroyed(ServletContextEvent event) {
        scheduler.shutdownNow();
    }
}
Where Task class implements Runnable.
public class Task implements Runnable {
    public void run() {
        // Do your job here.
    }
}
Or if your Java EE container is capable of this, use the container-provided job scheduling capabilities. The detailed answer depends on the container which you're using.
-2
            
            
        You can write a JAVA code which will trigger the JSP code periodically.If you have interest in this solution I can help you to do this (giving the sample code).
 
    
    
        Abhishek
        
- 2,095
- 2
- 21
- 25
- 
                    My point was to make an java application which will execute the JSP code(calling the URL) periodically. – Abhishek Feb 28 '11 at 13:59
 
     
     
    