Saturday, May 9, 2009

Servlet Listener Java

web.xml



TestNew


listener.TestListener



package listener;

import java.util.Timer;
import java.util.TimerTask;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;


/**
* Servlet implementation class for Servlet: TestListener
*
*/
public class TestListener implements ServletContextListener{
public void contextInitialized(ServletContextEvent sev){
Timer timer=new Timer(true);
timer.scheduleAtFixedRate(new Task(),0,1000);
}

public void contextDestroyed(ServletContextEvent scv){
}

class Task extends TimerTask{
public void run(){
System.out.println("Hello");
}
}
}

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails