Использование TaskQueue API
public class Enqueue extends HttpServlet {
private static final Logger log = Logger.getLogger(Enqueue.class.getName());
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String param1= request.getParameter("param1");
String param2= request.getParameter("param2");
String time = request.getParameter("time");
int timer = Integer.parseInt(time) * 1000;//sec to millisec
log.info("Executing in "+ timer+" seconds");
// Add the task to the default queue.
// Execute in 5 seconds
Queue queue = QueueFactory.getDefaultQueue();
queue.add(TaskOptions.Builder.withUrl("/index1").param("param1", param1)
.param("param2", param2)
.countdownMillis(time));
response.sendRedirect("/");
}
}
Теперь определите работу в классе Index1
public class Index1 extends HttpServlet {
private static final Logger log = Logger.getLogger(Index1.class.getName());
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
String param1= req.getParameter("param1");
String param2= req.getParameter("param2");
log.info("Worker processing " + param1);
/*Define job to be executed*/
}
}