Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring调度程序工作不正常_Java_Spring - Fatal编程技术网

Java Spring调度程序工作不正常

Java Spring调度程序工作不正常,java,spring,Java,Spring,Weblogic 12上部署了Spring项目。 在这个项目中,很少有像这样的spring调度器 @Component public class ExampleScheduler { @Autowired ExampleService exampleService; @Scheduled(fixedDelay = 1000) private void run(){ exampleService.doSomething(); }

Weblogic 12上部署了Spring项目。 在这个项目中,很少有像这样的spring调度器

@Component
public class ExampleScheduler {

    @Autowired
    ExampleService exampleService;

    @Scheduled(fixedDelay = 1000)
    private void run(){
        exampleService.doSomething();
    }    
}
调度程序的设置:

<task:annotation-driven executor="executor" scheduler="scheduler"/>
<task:executor id="executor" pool-size="20"/>
<task:scheduler id="scheduler" pool-size="40"/>

和@EnableScheduling在带有@Configuration的类中

问题是fixedDelay可以正常工作两次,然后在迭代之间暂停大约1.5分钟。 我在计划注释中尝试了fixedRate或cron,但没有帮助


方法在调度任务中的工作时间为100ms,project有足够的内存,但调度程序的工作速度很慢。

fixedDelay参数的设计使下一个任务的计时器在前一个任务完成后启动。i、 e.如果你的任务运行了0.5秒,那么它实际上会每1.5秒重复一次

p、 所以fixedDelay最好避免多个进程试图互相击败并造成竞争条件。例如,您有一个更新某些值的计划任务,此过程可能需要0.1秒到5秒,但您希望每秒刷新一次。您将使用fixedDelay来避免多个线程试图同时完成同一任务,而使用旧数据的任务最后完成,因此可能会从新任务中删除正确的值

fixedRate从每个过程开始测量。这将是直截了当的:

@Scheduled(fixedRate=500)
因为您每半秒需要一次,cron不是最佳选择,因为它只能指定秒,但如果需要,它将如下所示,6个输入点和区域是可选的:

@Scheduled(zone = "EST", cron = "* * * * * *") 

您的类必须至少具有以下注释:

包org.springframework.scheduling.annotation

@Configuration
@EnableScheduling
您可以使用fixedDelay进行设置

@Scheduled(fixedDelay = 1000)
还包括:

  @Scheduled(fixedDelay = 1000, initialDelay = 1000)
或者使用fixedRate(当任务的每次执行都是独立的时)


您可以将XML与
@EnableScheduling
一起使用,但不应同时使用这两种格式。此外,您使用的是WebLogic,因此您可能应该使用托管线程池,而不是创建自己的线程池。
   @Scheduled(fixedRate = 1000)