package com.zdnst.common.infra.utils;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;public class ThreadPoolUtils { private static final int POOL_SIZE = 15; private static ExecutorService threadPool; public static ExecutorService getPool(){ if(null == threadPool) { threadPool = Executors.newFixedThreadPool(POOL_SIZE); } return threadPool; }}
public void setMinTimeValue(final Serializable key, final Serializable value, final Integer mins) { pool.submit(new Runnable(){ @Override public void run() { try { redisTemplate.opsForValue().set(key, value); if(mins!=null&&mins>0){ redisTemplate.expire(key,mins,TimeUnit.MINUTES); } } catch (ZdnstException e) { //打印服务层异常详情,注意第二个参数必须传打印异常堆栈 logger.error(Constants.EX_SERVICE_EXCEPTION + e.getMessage(), e); //必须抛出通知调用者 throw new ZdnstException(e.getCode(),e.getMessage()); } catch (Exception e) { //打印服务层异常详情,注意第二个参数必须传打印异常堆栈 logger.error(Constants.EX_SERVICE_EXCEPTION + e.getMessage(), e); //封装为服务层异常110网络超时后再抛出,必须抛出通知调用者 throw new ZdnstException(BaseCode.ERROR_CODE110,e.getMessage()); } } });}