Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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_Spring Batch - Fatal编程技术网

Java 如何作为后台线程启动Spring批处理作业

Java 如何作为后台线程启动Spring批处理作业,java,spring,spring-batch,Java,Spring,Spring Batch,我们希望在后台启动作业,这样它就不会使用应用程序中的所有资源,并且会影响应用程序的“正常”任务。它应该在运行的Java应用程序中启动,而不是从命令行执行 有人知道如何使用Spring调度作为后台任务/守护进程启动Spring批处理作业吗?经过进一步调查,我发现您可以为JobLauncher配置TaskExecuter。然后,您可以使用SimpleAsyncTaskExector并将其配置为deamon并设置线程优先级 @Bean public JobLauncher jobLauncher(fi

我们希望在后台启动作业,这样它就不会使用应用程序中的所有资源,并且会影响应用程序的“正常”任务。它应该在运行的Java应用程序中启动,而不是从命令行执行


有人知道如何使用Spring调度作为后台任务/守护进程启动Spring批处理作业吗?

经过进一步调查,我发现您可以为JobLauncher配置TaskExecuter。然后,您可以使用SimpleAsyncTaskExector并将其配置为deamon并设置线程优先级

@Bean
public JobLauncher jobLauncher(final JobRepository jobRepository, final TaskExecutor taskExecutor) {

    final SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(jobRepository);
    jobLauncher.setTaskExecutor(taskExecutor);
    return jobLauncher;
}

@Bean
public TaskExecutor taskExecutor() {

    SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
    taskExecutor.setDaemon(true);
    taskExecutor.setThreadPriority(Thread.MIN_PRIORITY);
    return taskExecutor;
}

经过进一步调查,我发现您可以为JobLauncher配置TaskExecuter。然后,您可以使用SimpleAsyncTaskExector并将其配置为deamon并设置线程优先级

@Bean
public JobLauncher jobLauncher(final JobRepository jobRepository, final TaskExecutor taskExecutor) {

    final SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(jobRepository);
    jobLauncher.setTaskExecutor(taskExecutor);
    return jobLauncher;
}

@Bean
public TaskExecutor taskExecutor() {

    SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
    taskExecutor.setDaemon(true);
    taskExecutor.setThreadPriority(Thread.MIN_PRIORITY);
    return taskExecutor;
}

您可以使用Spring Scheduler()来调度任务。至于资源消耗,有很多因素会影响它。更糟糕的情况是,如果需要,只需购买更多内存,因为内存相对便宜(也就是说,如果它托管在某个地方)。我知道我可以使用Spring调度程序,但我不是100%认为Spring调度程序实际上创建了一个具有低线程优先级的类似deamon的线程。有没有办法验证这一点?此外,在我的特定用例中,作业实际上应该只运行一次,并且不应该被安排重复它自己。我无法验证Spring调度程序是否将以低线程优先级运行。如果作业只运行一次,那么为其编写脚本可能会更容易。您可能可以使用Spring应用程序根据需要的条件执行该脚本。您可以使用Spring Scheduler()计划任务。至于资源消耗,有很多因素会影响它。更糟糕的情况是,如果需要,只需购买更多内存,因为内存相对便宜(也就是说,如果它托管在某个地方)。我知道我可以使用Spring调度程序,但我不是100%认为Spring调度程序实际上创建了一个具有低线程优先级的类似deamon的线程。有没有办法验证这一点?此外,在我的特定用例中,作业实际上应该只运行一次,并且不应该被安排重复它自己。我无法验证Spring调度程序是否将以低线程优先级运行。如果作业只运行一次,那么为其编写脚本可能会更容易。您可能可以使用Spring应用程序根据需要的条件执行该脚本。