Cha*_*ndz 4 java cron spring spring-mvc spring-scheduled
如何动态地使用Spring的@Scheduled注释?
CronTrigger(String expression, TimeZone timeZone)
Run Code Online (Sandbox Code Playgroud)
由于我在数据库中有多个时区,我该如何动态传递它们?
我在我的代码中试过这个:
TimeZone timezone = null;
String timezone1 = null;
public SchedulerBean(String timezone2)
{
this.timezone1 = timezone2;
//constructor
}
@Scheduled(cron="0 0 8 * * ?", zone =timezone.getTimeZone(timezone1) ) //Error at this line
public void sendQuestionNotif()
{
//......code
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误,
*Type mismatch: cannot convert from TimeZone to String*
Run Code Online (Sandbox Code Playgroud)
请帮我.因为我想根据时区触发cron.TIA.
注释参数不能动态设置.您可以通过编程方式执行此操作
class Scheduler implements Runnable {
public Scheduler(TaskScheduler scheduler, String timezone, String cron) {
scheduler.schedule(this, new CronTrigger(cron, TimeZone.getTimeZone(timezone)));
}
@Override
public void run() {
//
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14653 次 |
| 最近记录: |