如何在某个特定时间间隔自动运行gwt servlet?

发布于 2024-08-10 00:34:17 字数 116 浏览 3 评论 0原文

请帮助我解决这个问题...

在我的应用程序中,我有日历,用户可以在其中设置特定日期的事件.. 此事件信息存储在数据库中...... 现在我希望我的应用程序在指定的日期自动向该用户发送电子邮件......

Please help me about this issue...

In my application i have calender where user can set the events for particular day..
this event info is store in database....
now i want my application to automatically send an email to that user on that assigned day....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

画尸师 2024-08-17 00:34:17

对于如此简单的计时器任务,您并不明确需要 Quartz API。对于这个 java.util.TimerTask 是非常合适。

You don't explititly need the Quartz API for such a simple timer task. For this java.util.TimerTask is perfectly suitable.

古镇旧梦 2024-08-17 00:34:17

您必须使用调度程序(quartz)。大多数应用程序都使用它。特别是用于发送邮件。

http://www.roseindia.net/quartz/index.shtml

http://www.quartz-scheduler.org/

https://quartz.dev.java.net/

您可以安排调度程序在特定时间间隔执行某些操作。

You have to use scheduler(quartz).Most of the applications are using that.Particularly for sending mails.

http://www.roseindia.net/quartz/index.shtml

http://www.quartz-scheduler.org/

https://quartz.dev.java.net/

You can schedule the scheduler to do some action in particular time interval.

请恋爱 2024-08-17 00:34:17

您的 servlet 正在后端运行。因此,您所需要做的就是创建一个无限循环,定期检查是否需要发送电子邮件。

像这样:

public void run()
{
 isRunning = true;
 while (isRunning)
 {
  performSomething();

 try
 {
  Thread.sleep(someInterval);
 }
 catch (InterruptedException e)
 {
  isRunning = false;
 }

}

其中 PerformSomething();方法是同步方法:

public synchronized void performSomething()

Your servlet is running on the back-end. So all you need is to create an endless loop which is regulary checking if an email needs to be send out.

Something like this:

public void run()
{
 isRunning = true;
 while (isRunning)
 {
  performSomething();

 try
 {
  Thread.sleep(someInterval);
 }
 catch (InterruptedException e)
 {
  isRunning = false;
 }

}

Where the performSomething(); method is a synchornized method:

public synchronized void performSomething()
单调的奢华 2024-08-17 00:34:17

使用 cron 作业怎么样,您可以使用 cron 作业调用 URL,它可以是处理逻辑的 servlet。

How about using cron jobs, you can call URLs with cron job which can be your servlet that handle the logic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文