gpt4 book ai didi

java - 如何用java和glassfish实现每日定时任务?

转载 作者:行者123 更新时间:2023-11-30 08:01:13 24 4
gpt4 key购买 nike

我正在尝试用java实现一个每日计划任务,与glassfish一起工作,它是每天实现数据库的记录,是一个集合的应用程序,因此 balances 和 interest 他们必须每天更新。我正在使用:

  • Glassfish 4
  • Java EE 7 网络
  • JSF 2.2
  • hibernate 4.3.1

我看过Maven的例子,所以我还不清楚,如果有人实现并能帮助我,我将不胜感激

最佳答案

最后我成功了,显然glassfish有问题,带走了他,我回去补充。但是最后的代码是

@Singleton
@Startup

public class BackgroundJobManager {

@Schedule(hour="0", minute="0", second="0", persistent=false)
public void someDailyJob() {
// Do your job here which should run every start of day.
System.out.println("");
}

@Schedule(hour="*/1", minute="0", second="0", persistent=false)
public void someHourlyJob() {
// Do your job here which should run every hour of day.
}

@Schedule(hour="*", minute="*/15", second="0", persistent=false)
public void someQuarterlyJob() {
// Do your job here which should run every 15 minute of hour.
System.out.println("Imprimir cada 15 mins");
}

@Schedule(hour="*", minute="*/1", second="0", persistent=false)
public void someMinuteJob() {
// Do your job here which should run every minute of the hour.
System.out.println("Imprimir cada 1 mins");
}

此代码在@BalusC 的帖子中 JSF managed bean for scheduled tasks using a timer

关于java - 如何用java和glassfish实现每日定时任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37924604/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com