jenkins启动SringBoot偶然报错!!!
jenkins启动SpringBoot偶尔会报错!
启动SpringBoot的项目的时候。
1、环境
- springboot ;
- jdk 1.8 ;
- jenkins部署 。
2、代码
1.使用了AsyncTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;
import java.util.concurrent.Future;
@Component
public class AsyncTask {
@Autowired
private AsyncTaskService asyncTaskService;
private final static String CALL_BACK = "success";
@Async
public Future<String> addUserGroupReadCount(Integer groupId,Integer count) throws Exception {
asyncTaskService.addUserGroupReadCount(groupId,count);
return new AsyncResult<String>(CALL_BACK);
}
}
2.设置了AsyncTaskConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.lang.reflect.Method;
import java.util.concurrent.Executor;
@EnableAsync
@Configuration
@ComponentScan("com.meyoung.cloudguide.task")
public class AsyncTaskConfig implements AsyncConfigurer {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(10);
taskExecutor.setMaxPoolSize(500);
taskExecutor.setQueueCapacity(25);
taskExecutor.setAwaitTerminationSeconds(60);
taskExecutor.setThreadNamePrefix("MeYoungAsync-Manage-");
taskExecutor.initialize();
return taskExecutor;
}
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return new SpringAsyncExceptionHandler();
}
class SpringAsyncExceptionHandler implements AsyncUncaughtExcept