import java.util.TimerTask;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* 借款相关控制器
*
* @author Shine
* @Date 2018/1/11 14:54
*/
public class LogManager {
//日志记录操作延时
private final int OPERATE_DELAY_TIME = 10;
//异步操作记录日志的线程池
private ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(10);
private LogManager() {
}
public static LogManager logManager = new LogManager();
public static LogManager me() {
return logManager;
}
public void executeLog(TimerTask task) {
executor.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS);
}
}
法一:
/* public static TimerTask mongoIouOperateLog(Long userId, String userName, Integer tradeType, BigDecimal tradeAmountfinal ,Date tradeDate, String content, String remarks) {
return new TimerTask() {
@Override
public void run() {
try {
MongoIouOperateLog log = new MongoIouOperateLog();
log.setUserId(userId);
log.setUserName(userName);
log.setTradeType(tradeType);
log.setTradeAmount(tradeAmountfinal);
log.setTradeDate(tradeDate);
log.setContent(content);
log.setRemarks(remarks);
operateLogService.saveLog(log);
} catch (Exception e) {
logger.error("系统日志异常!", e);
}
}
};
}*/
法二:
public static TimerTask mongoIouOperateLog(final Long userId,final String userName, final Integer tradeType, final BigDecimal tradeAmountfinal ,final Date tradeDate, final String content, final String remarks) {
return new TimerTask() {
@Override
public void run() {
try {
operateLogService.saveLog( LogFactory.operateLog(userId,userName,PublicConstants.OPERATE_LOG.AGREE_BORROW.getTypeId(),tradeAmountfinal ,tradeDate,content,remarks));
} catch (Exception e) {
logger.error("系统日志异常!", e);
}
}
};
}