Commit e1f5d8cd authored by “dujiuxin”'s avatar “dujiuxin”

添加监控

parent 851fd3f5
......@@ -6,6 +6,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
@Configuration
//@EnableAsync
......@@ -17,13 +18,14 @@ public class ExecutorConfig {
//线程池维护线程的最少数量
taskExecutor.setCorePoolSize(10);
//线程池维护线程的最大数量
taskExecutor.setMaxPoolSize(20);
taskExecutor.setMaxPoolSize(100);
//线程池所使用的缓冲队列
taskExecutor.setQueueCapacity(50);
taskExecutor.setQueueCapacity(500);
//线程池维护线程所允许的空闲时间
taskExecutor.setKeepAliveSeconds(60);
taskExecutor.setAllowCoreThreadTimeOut(true);
taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
taskExecutor.setAwaitTerminationSeconds(60);
return taskExecutor;
}
......@@ -41,6 +43,7 @@ public class ExecutorConfig {
taskExecutor.setKeepAliveSeconds(60);
taskExecutor.setAllowCoreThreadTimeOut(true);
taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
taskExecutor.setAwaitTerminationSeconds(60);
return taskExecutor;
}
......
......@@ -26,7 +26,7 @@ public class TemplateTaskPoolConfig {
executor.setThreadNamePrefix("gt-tempmsg-exec");
//如果执行程序尚未关闭,则位于工作队列头部的任务将被删除,然后重试执行程序(如果再次失败,则重复此过程)
//该策略就稍微复杂一些,在pool没有关闭的前提下首先丢掉缓存在队列中的最早的任务,然后重新尝试运行该任务。这个策略需要适当小心*/
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardOldestPolicy());
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.setAwaitTerminationSeconds(60);
return executor;
......@@ -47,7 +47,7 @@ public class TemplateTaskPoolConfig {
executor.setThreadNamePrefix("gt-pushmsg-exec");
//如果执行程序尚未关闭,则位于工作队列头部的任务将被删除,然后重试执行程序(如果再次失败,则重复此过程)
//该策略就稍微复杂一些,在pool没有关闭的前提下首先丢掉缓存在队列中的最早的任务,然后重新尝试运行该任务。这个策略需要适当小心*/
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardOldestPolicy());
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.setAwaitTerminationSeconds(60);
return executor;
......
package com.zfxftech.telmarket.task.monitor;
import com.zfxftech.telmarket.service.redis.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Date;
/**
* 处理委托单自动买入成交
* */
@Slf4j
@Component
public class MonitorTask {
@Autowired
@Qualifier("redisServiceNoWrapper")
private RedisService redisService;
//@ApiOperation(value = "服务监控", notes = "服务监控", httpMethod = "GET")
@Scheduled(cron = "0/2 * * * * ? ")
public void moniter() throws IOException {
String key = "GT:MONITOR:INVEST:TASK:PRICE";
redisService.set(key,String.valueOf((new Date()).getTime()));
}
}
......@@ -46,7 +46,7 @@ public class AsyncExecturConfig implements SchedulingConfigurer, AsyncConfigurer
@Bean(destroyMethod = "shutdown")
public ThreadPoolTaskScheduler taskScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(100);
scheduler.setPoolSize(200);
scheduler.setThreadNamePrefix("sch-task-");
scheduler.setAwaitTerminationSeconds(60);
scheduler.setWaitForTasksToCompleteOnShutdown(true);
......@@ -68,10 +68,10 @@ public class AsyncExecturConfig implements SchedulingConfigurer, AsyncConfigurer
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor threadPoolTaskExecutor=new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setCorePoolSize(20);
threadPoolTaskExecutor.setMaxPoolSize(50);
threadPoolTaskExecutor.setQueueCapacity(100);
threadPoolTaskExecutor.setMaxPoolSize(200);
threadPoolTaskExecutor.setQueueCapacity(1000);
threadPoolTaskExecutor.setKeepAliveSeconds(300);
threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
threadPoolTaskExecutor.setThreadNamePrefix("async-executor-");
threadPoolTaskExecutor.initialize();
return threadPoolTaskExecutor;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment