Commit cc3e8bf05292d3cd914c4b6d5dbe965e60885c87

Authored by 胡翰林
1 parent 67dfd498

mass同步接口测试

... ... @@ -4,7 +4,9 @@ import org.springframework.boot.SpringApplication;
4 4 import org.springframework.boot.autoconfigure.SpringBootApplication;
5 5 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
6 6 import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
  7 +import org.springframework.scheduling.annotation.EnableScheduling;
7 8
  9 +@EnableScheduling
8 10 @SpringBootApplication(exclude = {
9 11 DataSourceAutoConfiguration.class,
10 12 DataSourceTransactionManagerAutoConfiguration.class
... ...
... ... @@ -2,20 +2,32 @@ package com.mass.config;
2 2
3 3 import org.springframework.context.annotation.Bean;
4 4 import org.springframework.context.annotation.Configuration;
  5 +import org.springframework.scheduling.TaskScheduler;
5 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 14 @Configuration
9   -@EnableScheduling
10   -public class TaskExecutorConfig {
  15 +public class TaskExecutorConfig implements SchedulingConfigurer {
11 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 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 3 import com.mass.service.UserSyncService;
4 4 import lombok.extern.slf4j.Slf4j;
5 5 import org.springframework.data.repository.query.Param;
6   -import org.springframework.scheduling.annotation.Scheduled;
7 6 import org.springframework.web.bind.annotation.GetMapping;
8 7 import org.springframework.web.bind.annotation.RequestMapping;
9 8 import org.springframework.web.bind.annotation.RestController;
... ...
... ... @@ -49,7 +49,7 @@ public class UserSyncService {
49 49
50 50 @Scheduled(cron = "*/5 * * * * ?")
51 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 16
17 17 mass:
18 18 domain: http://53.1.230.5:8159
  19 + syscode: da3fb2fd714e4178a7ab93d88aadb430
19 20 userListUrl: /UUDB/user/list
20 21 userUpdateListUrl: /UUDB/user/updateList
21 22 orgListUrl: /UUDB/org/list
... ...