Merge branch 'master' into v4.1_dev
This commit is contained in:
@@ -4,9 +4,14 @@
|
||||
package com.jeesite.modules.sys.utils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import io.netty.util.concurrent.DefaultThreadFactory;
|
||||
import org.apache.ibatis.mapping.SqlCommandType;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||
@@ -39,7 +44,12 @@ import eu.bitwalker.useragentutils.UserAgent;
|
||||
* @version 2017-11-7
|
||||
*/
|
||||
public class LogUtils {
|
||||
|
||||
|
||||
//采用线程池优化性能
|
||||
private static ExecutorService logThreadPool = new ThreadPoolExecutor(5, 20,
|
||||
60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),
|
||||
new DefaultThreadFactory("log-save"));
|
||||
|
||||
/**
|
||||
* 静态内部类,延迟加载,懒汉式,线程安全的单例模式
|
||||
*/
|
||||
@@ -101,22 +111,21 @@ public class LogUtils {
|
||||
if (ex != null){
|
||||
throwable = ExceptionUtils.getThrowable(request);
|
||||
}
|
||||
|
||||
|
||||
// 异步保存日志
|
||||
new SaveLogThread(log, handler, request.getContextPath(), throwable).start();
|
||||
logThreadPool.submit(new SaveLogTask(log, handler, request.getContextPath(), throwable));
|
||||
}
|
||||
/**
|
||||
* 保存日志线程
|
||||
*/
|
||||
public static class SaveLogThread extends Thread{
|
||||
public static class SaveLogTask extends Thread{
|
||||
|
||||
private Log log;
|
||||
private Object handler;
|
||||
private String contextPath;
|
||||
private Throwable throwable;
|
||||
|
||||
public SaveLogThread(Log log, Object handler, String contextPath, Throwable throwable){
|
||||
super(SaveLogThread.class.getSimpleName());
|
||||
public SaveLogTask(Log log, Object handler, String contextPath, Throwable throwable){
|
||||
this.log = log;
|
||||
this.handler = handler;
|
||||
this.contextPath = contextPath;
|
||||
|
||||
Reference in New Issue
Block a user