Showing
5 changed files
with
26 additions
and
12 deletions
| @@ -4,7 +4,9 @@ import org.springframework.boot.SpringApplication; | @@ -4,7 +4,9 @@ import org.springframework.boot.SpringApplication; | ||
| 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; | 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | 5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; |
| 6 | import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; | 6 | import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; |
| 7 | +import org.springframework.scheduling.annotation.EnableScheduling; | ||
| 7 | 8 | ||
| 9 | +@EnableScheduling | ||
| 8 | @SpringBootApplication(exclude = { | 10 | @SpringBootApplication(exclude = { |
| 9 | DataSourceAutoConfiguration.class, | 11 | DataSourceAutoConfiguration.class, |
| 10 | DataSourceTransactionManagerAutoConfiguration.class | 12 | DataSourceTransactionManagerAutoConfiguration.class |
| @@ -2,20 +2,32 @@ package com.mass.config; | @@ -2,20 +2,32 @@ package com.mass.config; | ||
| 2 | 2 | ||
| 3 | import org.springframework.context.annotation.Bean; | 3 | import org.springframework.context.annotation.Bean; |
| 4 | import org.springframework.context.annotation.Configuration; | 4 | import org.springframework.context.annotation.Configuration; |
| 5 | +import org.springframework.scheduling.TaskScheduler; | ||
| 5 | import org.springframework.scheduling.annotation.EnableScheduling; | 6 | import org.springframework.scheduling.annotation.EnableScheduling; |
| 6 | -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | 7 | +import org.springframework.scheduling.annotation.SchedulingConfigurer; |
| 8 | +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; | ||
| 9 | +import org.springframework.scheduling.config.ScheduledTaskRegistrar; | ||
| 10 | + | ||
| 11 | +import java.util.concurrent.ThreadPoolExecutor; | ||
| 12 | + | ||
| 7 | 13 | ||
| 8 | @Configuration | 14 | @Configuration |
| 9 | -@EnableScheduling | ||
| 10 | -public class TaskExecutorConfig { | 15 | +public class TaskExecutorConfig implements SchedulingConfigurer { |
| 11 | @Bean | 16 | @Bean |
| 12 | - public ThreadPoolTaskExecutor taskExecutor() { | ||
| 13 | - ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | ||
| 14 | - executor.setCorePoolSize(10); | ||
| 15 | - executor.setMaxPoolSize(50); | ||
| 16 | - executor.setQueueCapacity(1000); | ||
| 17 | - executor.setKeepAliveSeconds(60); | ||
| 18 | - executor.setThreadNamePrefix("task-executor-"); | 17 | + public TaskScheduler taskScheduler() { |
| 18 | + ThreadPoolTaskScheduler executor = new ThreadPoolTaskScheduler(); | ||
| 19 | + executor.setPoolSize(10); | ||
| 20 | + executor.setThreadNamePrefix("task-thread"); | ||
| 21 | + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); | ||
| 22 | + executor.initialize(); | ||
| 19 | return executor; | 23 | return executor; |
| 20 | } | 24 | } |
| 25 | + | ||
| 26 | + | ||
| 27 | + @Override | ||
| 28 | + public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { | ||
| 29 | + scheduledTaskRegistrar.setTaskScheduler(taskScheduler()); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + | ||
| 21 | } | 33 | } |
| @@ -3,7 +3,6 @@ package com.mass.controller; | @@ -3,7 +3,6 @@ package com.mass.controller; | ||
| 3 | import com.mass.service.UserSyncService; | 3 | import com.mass.service.UserSyncService; |
| 4 | import lombok.extern.slf4j.Slf4j; | 4 | import lombok.extern.slf4j.Slf4j; |
| 5 | import org.springframework.data.repository.query.Param; | 5 | import org.springframework.data.repository.query.Param; |
| 6 | -import org.springframework.scheduling.annotation.Scheduled; | ||
| 7 | import org.springframework.web.bind.annotation.GetMapping; | 6 | import org.springframework.web.bind.annotation.GetMapping; |
| 8 | import org.springframework.web.bind.annotation.RequestMapping; | 7 | import org.springframework.web.bind.annotation.RequestMapping; |
| 9 | import org.springframework.web.bind.annotation.RestController; | 8 | import org.springframework.web.bind.annotation.RestController; |
| @@ -49,7 +49,7 @@ public class UserSyncService { | @@ -49,7 +49,7 @@ public class UserSyncService { | ||
| 49 | 49 | ||
| 50 | @Scheduled(cron = "*/5 * * * * ?") | 50 | @Scheduled(cron = "*/5 * * * * ?") |
| 51 | public void snyc() { | 51 | public void snyc() { |
| 52 | - log.info("====test"); | 52 | + log.info( Thread.currentThread().getName()+"====test"); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | 55 |
| @@ -16,6 +16,7 @@ logging: | @@ -16,6 +16,7 @@ logging: | ||
| 16 | 16 | ||
| 17 | mass: | 17 | mass: |
| 18 | domain: http://53.1.230.5:8159 | 18 | domain: http://53.1.230.5:8159 |
| 19 | + syscode: da3fb2fd714e4178a7ab93d88aadb430 | ||
| 19 | userListUrl: /UUDB/user/list | 20 | userListUrl: /UUDB/user/list |
| 20 | userUpdateListUrl: /UUDB/user/updateList | 21 | userUpdateListUrl: /UUDB/user/updateList |
| 21 | orgListUrl: /UUDB/org/list | 22 | orgListUrl: /UUDB/org/list |