You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Cameron <ca...@gmail.com> on 2006/07/20 05:52:38 UTC
Tomcat, Timer and TimerTask question
Hello
Just trying to schedule a batch email run using Timer and TimerTask framework on
Tomcat 4.1.31
Found the following example from http://www.javapractices.com/Topic54.cjp
Trying trying to test this scheduling mechanism first just by printing to
System.out first... (see below)
It does not seem to run. Code compiles properly in eclipse.
Does tomcat require any libraries... There is no errors in tomcat either.
public final class schedEmailUser extends TimerTask {
public static void main (String[] args) {
TimerTask schedEmail = new schedEmailUser();
Timer timer = new Timer();
Calendar date = Calendar.getInstance();
date.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
date.set(Calendar.HOUR, 12);
date.set(Calendar.MINUTE, 10);
date.set(Calendar.SECOND, 0);
date.set(Calendar.MILLISECOND, 0);
timer.scheduleAtFixedRate(new schedEmailUser(), date.getTime(), 1000 * 60 *
60 * 24);
System.out.println("In main Sending email...");
timer.cancel();
}
public void run(){
System.out.println("In run Sending email...");
}
} //end schedEmailUser
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat, Timer and TimerTask question
Posted by Vinu Varghese <vi...@x-minds.org>.
Hi,
What is the main for ? , Once u have main , why u need tomcat to run
this ?
Pls let me know how u are running this ?
Cheers
Vinu
Cameron wrote:
> Hello
>
> Just trying to schedule a batch email run using Timer and TimerTask framework on
> Tomcat 4.1.31
>
> Found the following example from http://www.javapractices.com/Topic54.cjp
>
> Trying trying to test this scheduling mechanism first just by printing to
> System.out first... (see below)
>
> It does not seem to run. Code compiles properly in eclipse.
>
> Does tomcat require any libraries... There is no errors in tomcat either.
>
>
> public final class schedEmailUser extends TimerTask {
>
> public static void main (String[] args) {
> TimerTask schedEmail = new schedEmailUser();
>
> Timer timer = new Timer();
> Calendar date = Calendar.getInstance();
> date.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
> date.set(Calendar.HOUR, 12);
> date.set(Calendar.MINUTE, 10);
> date.set(Calendar.SECOND, 0);
> date.set(Calendar.MILLISECOND, 0);
>
> timer.scheduleAtFixedRate(new schedEmailUser(), date.getTime(), 1000 * 60 *
> 60 * 24);
> System.out.println("In main Sending email...");
> timer.cancel();
> }
>
> public void run(){
> System.out.println("In run Sending email...");
> }
> } //end schedEmailUser
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
--
........................................
Vinu Varghese
vinu@x-minds.org
www.x-minds.org
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat, Timer and TimerTask question
Posted by Jon Wingfield <jo...@mkodo.com>.
It's not running because you schedule the task and then immediately
cancel it. The scheduleAtFixedRate call doesn't block.
Cameron wrote:
> Hello
>
> Just trying to schedule a batch email run using Timer and TimerTask framework on
> Tomcat 4.1.31
>
> Found the following example from http://www.javapractices.com/Topic54.cjp
>
> Trying trying to test this scheduling mechanism first just by printing to
> System.out first... (see below)
>
> It does not seem to run. Code compiles properly in eclipse.
>
> Does tomcat require any libraries... There is no errors in tomcat either.
>
>
> public final class schedEmailUser extends TimerTask {
>
> public static void main (String[] args) {
> TimerTask schedEmail = new schedEmailUser();
>
> Timer timer = new Timer();
> Calendar date = Calendar.getInstance();
> date.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
> date.set(Calendar.HOUR, 12);
> date.set(Calendar.MINUTE, 10);
> date.set(Calendar.SECOND, 0);
> date.set(Calendar.MILLISECOND, 0);
>
> timer.scheduleAtFixedRate(new schedEmailUser(), date.getTime(), 1000 * 60 *
> 60 * 24);
> System.out.println("In main Sending email...");
> timer.cancel();
> }
>
> public void run(){
> System.out.println("In run Sending email...");
> }
> } //end schedEmailUser
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat, Timer and TimerTask question
Posted by Christopher Schultz <ch...@christopherschultz.net>.
Cameron,
> Just trying to schedule a batch email run using Timer and TimerTask framework on
> Tomcat 4.1.31
You might also consider simply using a cron job (or win32 equivalent)
for "real" batch jobs, instead of having your app server manage your
batch jobs.
-chris