To set the global timer you need to add a servlet to Web. XML, set Load-on-startup to 1, and then open the timer in the servlet's init () with the following code:
1. Web. xml
<servlet><servlet-name>backup</servlet-name><servlet-class> locationservice.backup.backup</servlet-class><load-on-startup>1</load-on-startup></ Servlet>
2. Backup.java
public class Backup extends HttpServlet { private static final long serialversionuid = 1L; private static final Logger Logger = Logger.getlogger (backup.class); public void Init () throws Servletexception {timertask bakcuptask = new TimerTask () {public void run () { try {b Ackup ();} catch (Exception e) {e.printstacktrace ();} } }; /* Schedule the task to be run every hours * /Timer time = new timer (); Time.scheduleatfixedrate (Bakcuptask, New Date (), 1000*60*60*24); } ...
STRUTS2 Setting up Global timer