Commit 3699a00a by 袁伟铭

1.0.0

parent 59e3e981
......@@ -110,13 +110,13 @@ public class ApiController {
// 调试日志
if (ApiUtils.DEBUG) {
System.out.println("API DEBUG ACTION \n[from=" + form + "]" //
+ "\n[resp=" + JSON.toJSONString(resp) + "]" //
System.out.println("API DEBUG ACTION \n[from=" + form + "]"
+ "\n[resp=" + JSON.toJSONString(resp) + "]"
+ "\n[time=" + (System.currentTimeMillis() - start) + "ms]");
}
String clientIP = ServletUtil.getClientIP(request);
apiService.addLog(form, clientIP, logType, resp.getMsg(), stackTrace, System.currentTimeMillis() - start);
String clientIp = ServletUtil.getClientIP(request);
apiService.addLog(form, clientIp, logType, resp.getMsg(), stackTrace, System.currentTimeMillis() - start);
return resp;
}
......
......@@ -7,36 +7,52 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
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.util.concurrent.Executor;
/**
* 异步执行配置
* <p>
* 注解ConditionalOnProperty(value = "async.pool.enable", havingValue = "true")
* 当获取到async.pool.enable的值等于havingValue的值时才加载配置
*
* @author wilmiam
* @since 2021-07-09 17:50
*/
@Configuration
@ConditionalOnProperty(value = "async.pool.enable", havingValue = "true")
@EnableAsync
@ConditionalOnProperty(value = "task.pool.enable", havingValue = "true")
public class AsyncConfig implements AsyncConfigurer {
private static final Logger log = LoggerFactory.getLogger(AsyncConfig.class);
@Value("${async.pool.core-pool-size:5}")
/**
* 核心线程池大小
*/
@Value("${task.pool.core-pool-size:5}")
private int corePoolSize;
@Value("${async.pool.queue-capacity:10}")
/**
* 最大线程数
*/
@Value("${task.pool.max-pool-size:15}")
private int maxPoolSize;
@Value("${async.pool.max-pool-size:25}")
/**
* 队列容量
*/
@Value("${task.pool.queue-capacity:20}")
private int queueCapacity;
@Value("${async.pool.keepalive-seconds:10}")
/**
* 活跃时间
*/
@Value("${task.pool.keep-alive-seconds:30}")
private int threadTimeout;
@Override
public Executor getAsyncExecutor() {
log.debug(">> 初始化spring线程池...");
log.info(">> 初始化spring线程池...");
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
// 当一个任务通过execute(Runnable)方法欲添加到线程池时:
......@@ -56,6 +72,8 @@ public class AsyncConfig implements AsyncConfigurer {
// 线程池维护线程所允许的空闲时间
threadPoolTaskExecutor.setKeepAliveSeconds(threadTimeout);
threadPoolTaskExecutor.setThreadNamePrefix("cloud-async-");
// don't forget to initialize the thread pool
threadPoolTaskExecutor.initialize();
......
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.zq.common.config.limit;
import com.alibaba.fastjson.JSON;
......@@ -42,6 +27,8 @@ import java.util.Collections;
import java.util.List;
/**
* 限流切面类
*
* @author wilmiam
* @since 2021-07-09 17:51
*/
......
package com.zq.common.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* 系统日志(SysLog)实体类
*
* @author makejava
* @since 2021-07-12 12:43:07
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TableName(value = "sys_log")
public class SysLog {
/**
* ID
*/
@ApiModelProperty("ID")
private Long logId;
/**
* description
*/
private String description;
/**
* logType
*/
private String logType;
/**
* method
*/
private String method;
/**
* params
*/
private String params;
/**
* requestIp
*/
private String requestIp;
/**
* time
*/
private Long time;
/**
* username
*/
private String username;
/**
* address
*/
private String address;
/**
* browser
*/
private String browser;
/**
* exceptionDetail
*/
private String exceptionDetail;
/**
* createTime
*/
private Date createTime;
}
\ No newline at end of file
......@@ -43,5 +43,19 @@ jwt:
# 续期时间范围,默认 1小时,这里单位毫秒
renew: 3600000
#线程池配置
task:
pool:
# 是否启用线程池
enable: true
# 核心线程池大小
core-pool-size: 5
# 最大线程数
max-pool-size: 15
# 队列容量
queue-capacity: 20
# 活跃时间
keep-alive-seconds: 30
#日志等级
logging.level.com.zq.*: debug
......@@ -42,3 +42,17 @@ jwt:
detect: 1800000
# 续期时间范围,默认 1小时,这里单位毫秒
renew: 3600000
#线程池配置
task:
pool:
# 是否启用线程池
enable: true
# 核心线程池大小
core-pool-size: 5
# 最大线程数
max-pool-size: 15
# 队列容量
queue-capacity: 20
# 活跃时间
keep-alive-seconds: 30
......@@ -42,3 +42,17 @@ jwt:
detect: 1800000
# 续期时间范围,默认 1小时,这里单位毫秒
renew: 3600000
#线程池配置
task:
pool:
# 是否启用线程池
enable: true
# 核心线程池大小
core-pool-size: 5
# 最大线程数
max-pool-size: 15
# 队列容量
queue-capacity: 20
# 活跃时间
keep-alive-seconds: 30
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.zq.system.config.thread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* 异步任务线程池装配类
* @author https://juejin.im/entry/5abb8f6951882555677e9da2
* @date 2019年10月31日15:06:18
*/
@Slf4j
@Configuration
public class AsyncTaskExecutePool implements AsyncConfigurer {
/** 注入配置类 */
private final AsyncTaskProperties config;
public AsyncTaskExecutePool(AsyncTaskProperties config) {
this.config = config;
}
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
//核心线程池大小
executor.setCorePoolSize(config.getCorePoolSize());
//最大线程数
executor.setMaxPoolSize(config.getMaxPoolSize());
//队列容量
executor.setQueueCapacity(config.getQueueCapacity());
//活跃时间
executor.setKeepAliveSeconds(config.getKeepAliveSeconds());
//线程名字前缀
executor.setThreadNamePrefix("el-async-");
// setRejectedExecutionHandler:当pool已经达到max size的时候,如何处理新任务
// CallerRunsPolicy:不在新线程中执行任务,而是由调用者所在的线程来执行
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.initialize();
return executor;
}
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return (throwable, method, objects) -> {
log.error("===="+throwable.getMessage()+"====", throwable);
log.error("exception method:"+method.getName());
};
}
}
// /*
// * Copyright 2019-2020 Zheng Jie
// *
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// */
// package com.zq.system.config.thread;
//
// import lombok.extern.slf4j.Slf4j;
// import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
// import org.springframework.context.annotation.Configuration;
// import org.springframework.scheduling.annotation.AsyncConfigurer;
// import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
//
// import java.util.concurrent.Executor;
// import java.util.concurrent.ThreadPoolExecutor;
//
// /**
// * 异步任务线程池装配类
// * @author https://juejin.im/entry/5abb8f6951882555677e9da2
// * @date 2019年10月31日15:06:18
// */
// @Slf4j
// @Configuration
// public class AsyncTaskExecutePool implements AsyncConfigurer {
//
// /** 注入配置类 */
// private final AsyncTaskProperties config;
//
// public AsyncTaskExecutePool(AsyncTaskProperties config) {
// this.config = config;
// }
//
// @Override
// public Executor getAsyncExecutor() {
// ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
// //核心线程池大小
// executor.setCorePoolSize(config.getCorePoolSize());
// //最大线程数
// executor.setMaxPoolSize(config.getMaxPoolSize());
// //队列容量
// executor.setQueueCapacity(config.getQueueCapacity());
// //活跃时间
// executor.setKeepAliveSeconds(config.getKeepAliveSeconds());
// //线程名字前缀
// executor.setThreadNamePrefix("el-async-");
// // setRejectedExecutionHandler:当pool已经达到max size的时候,如何处理新任务
// // CallerRunsPolicy:不在新线程中执行任务,而是由调用者所在的线程来执行
// executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// executor.initialize();
// return executor;
// }
//
// @Override
// public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
// return (throwable, method, objects) -> {
// log.error("===="+throwable.getMessage()+"====", throwable);
// log.error("exception method:"+method.getName());
// };
// }
// }
......@@ -65,17 +65,6 @@ spring:
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
open-in-view: true
task:
pool:
# 核心线程池大小
core-pool-size: 10
# 最大线程数
max-pool-size: 30
# 活跃时间
keep-alive-seconds: 60
# 队列容量
queue-capacity: 50
#七牛云
qiniu:
# 文件大小 /M
......
......@@ -46,7 +46,6 @@ public class UserService {
String code = RandomUtil.randomNumbers(6);
String content = "您的验证码为:" + code + "(5分钟内有效)。为了保障信息安全,如非本人操作请忽略本短信。";
// TODO 发送验证码
log.info(">> phone: {}, sendCode: {}, success: ", phone, code);
redisUtils.setStr(UserCacheKeys.authCodeKey(phone), code, 5);
}
......
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