|
|
|
|
@ -21,6 +21,7 @@ import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
|
|
|
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
|
|
|
|
|
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
@ -189,15 +190,108 @@ public class DfxAgentConfiguration {
|
|
|
|
|
return new DataSourceTransactionManager(dataSource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean(name = "threadPoolTaskExecutor")
|
|
|
|
|
public Executor threadPoolTaskExecutor() {
|
|
|
|
|
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
|
|
|
|
|
threadPoolTaskExecutor.setCorePoolSize(30); // 최소 쓰레드
|
|
|
|
|
threadPoolTaskExecutor.setMaxPoolSize(300); // 최대 쓰레드
|
|
|
|
|
threadPoolTaskExecutor.setQueueCapacity(300); // 대기 큐
|
|
|
|
|
threadPoolTaskExecutor.setThreadNamePrefix("dfxExecutor-");
|
|
|
|
|
threadPoolTaskExecutor.setWaitForTasksToCompleteOnShutdown(true); // 종료 시 대기 여부
|
|
|
|
|
threadPoolTaskExecutor.initialize();
|
|
|
|
|
return threadPoolTaskExecutor;
|
|
|
|
|
@Bean(name = "dropBoxProcessorThreadPoolTaskExecutor")
|
|
|
|
|
public Executor dropBoxProcessorThreadPoolTaskExecutor() {
|
|
|
|
|
ThreadPoolTaskExecutor dropBoxProcessorThreadPoolTaskExecutor = new ThreadPoolTaskExecutor();
|
|
|
|
|
dropBoxProcessorThreadPoolTaskExecutor.setCorePoolSize(30); // 최소 쓰레드
|
|
|
|
|
dropBoxProcessorThreadPoolTaskExecutor.setMaxPoolSize(300); // 최대 쓰레드
|
|
|
|
|
dropBoxProcessorThreadPoolTaskExecutor.setQueueCapacity(300); // 대기 큐
|
|
|
|
|
dropBoxProcessorThreadPoolTaskExecutor.setThreadNamePrefix("dfxExecutor-");
|
|
|
|
|
dropBoxProcessorThreadPoolTaskExecutor.setWaitForTasksToCompleteOnShutdown(true); // 종료 시 대기 여부
|
|
|
|
|
dropBoxProcessorThreadPoolTaskExecutor.initialize();
|
|
|
|
|
return dropBoxProcessorThreadPoolTaskExecutor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean(name = "scheduledPostmanThreadPoolTaskScheduler")
|
|
|
|
|
public ThreadPoolTaskScheduler scheduledPostmanThreadPoolTaskScheduler() {
|
|
|
|
|
ThreadPoolTaskScheduler scheduledPostmanThreadPoolTaskScheduler = new ThreadPoolTaskScheduler();
|
|
|
|
|
/**
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
public class SchedulerConfig {
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public ThreadPoolTaskScheduler taskScheduler() {
|
|
|
|
|
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
|
|
|
|
scheduler.setPoolSize(5);
|
|
|
|
|
scheduler.setThreadNamePrefix("dynamic-scheduler-");
|
|
|
|
|
scheduler.initialize();
|
|
|
|
|
return scheduler;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
import org.springframework.scheduling.Trigger;
|
|
|
|
|
import org.springframework.scheduling.TriggerContext;
|
|
|
|
|
import org.springframework.scheduling.support.CronTrigger;
|
|
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.concurrent.ScheduledFuture;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class DynamicSchedulerService {
|
|
|
|
|
|
|
|
|
|
private final ThreadPoolTaskScheduler taskScheduler;
|
|
|
|
|
private ScheduledFuture<?> scheduledFuture;
|
|
|
|
|
private String currentCron = "0/10 * * * * *"; // 10초마다
|
|
|
|
|
|
|
|
|
|
public DynamicSchedulerService(ThreadPoolTaskScheduler taskScheduler) {
|
|
|
|
|
this.taskScheduler = taskScheduler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void startDynamicTask() {
|
|
|
|
|
scheduledFuture = taskScheduler.schedule(this::runTask, new CronTrigger(currentCron));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updateCron(String newCron) {
|
|
|
|
|
stopTask();
|
|
|
|
|
this.currentCron = newCron;
|
|
|
|
|
startDynamicTask();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void stopTask() {
|
|
|
|
|
if (scheduledFuture != null) {
|
|
|
|
|
scheduledFuture.cancel(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void runTask() {
|
|
|
|
|
System.out.println("작업 실행: " + new Date());
|
|
|
|
|
// 실제 작업 로직
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class ScheduleController {
|
|
|
|
|
|
|
|
|
|
private final DynamicSchedulerService schedulerService;
|
|
|
|
|
|
|
|
|
|
@PostMapping("/start")
|
|
|
|
|
public String start() {
|
|
|
|
|
schedulerService.startDynamicTask();
|
|
|
|
|
return "스케줄 시작";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/update")
|
|
|
|
|
public String update(@RequestParam String cron) {
|
|
|
|
|
schedulerService.updateCron(cron);
|
|
|
|
|
return "크론 변경됨: " + cron;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/stop")
|
|
|
|
|
public String stop() {
|
|
|
|
|
schedulerService.stopTask();
|
|
|
|
|
return "스케줄 정지됨";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
return scheduledPostmanThreadPoolTaskScheduler;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|