Evilsithgirl Evilsithgirl - 1 year ago 141
Java Question

Java Time Delay

I am having trouble with the following bit of code.

//Send Creation email
ListServDAO.sendCreateEmail(orgId, full, request.getSession().getServletContext());
//Force a 1 minute pause
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
//Send add members email
ListServDAO.sendAddMembersEmail(orgId, request.getSession().getServletContext());
}, 0, 60 * 1000);

The sendAddMembersEmail function does not wait 1 minute to send after the sendCreateEmail function call. I am not sure why it is not waiting even after reading the java API. I do not wish to use the Thread.sleep method because I want the user to be able to use the application while waiting for the emails to send.

Answer Source

You have an extra zero.

What you are calling is Delayed with a Fixed-Delay Repeat Execution and what you want is a Single Delay Non Repeat execution.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download