/** * Description: 通过线程池来处理消息<br> * * @author 王伟<br> * @taskId <br> * @param channel * @param message * @throws InterruptedException <br> */ public static void execute(String channel, Runnable message) { synchronized (channel) { ThreadPoolExecutor executor = executorMap.get(channel); if (executor == null) { executor = createThreadPoolExecutor(); executorMap.put(channel, executor); } BlockingQueue<Runnable> bq = executor.getQueue(); // 当线程池中的队列出现阻塞后,暂停从redis中进行获取 try { while (bq.remainingCapacity() == 0 && executor.getMaximumPoolSize() == executor.getPoolSize()) { LoggerUtil.info("wait message[{0}] execute, current pool size is [{1}]", channel, bq.size()); Thread.sleep(100); } executor.execute(message); } catch (InterruptedException e) { LoggerUtil.error(e); } } }
/** * Description: <br> * * @author 王伟<br> * @taskId <br> * @param key * @param valueLoader * @return <br> */ @Override public <T> T get(Object key, Callable<T> valueLoader) { T result = get(CacheConstant.DEFAULT_CACHE_DIR, key.toString()); if (result == null) { try { result = valueLoader.call(); put(CacheConstant.DEFAULT_CACHE_DIR, key.toString(), result); } catch (Exception e) { LoggerUtil.error(e); } } return result; }
/** * Description: <br> * * @author 王伟<br> * @taskId <br> * @param key * @param valueLoader * @return <br> */ @Override public <T> T get(Object key, Callable<T> valueLoader) { T result = get(CacheConstant.DEFAULT_CACHE_DIR, key.toString()); if (result == null) { try { result = valueLoader.call(); put(CacheConstant.DEFAULT_CACHE_DIR, key.toString(), result); } catch (Exception e) { LoggerUtil.error(e); } } return result; }
public static <T extends Serializable> int flowStart(T bean, String flowName, boolean throwable) { Assert.notNull(bean, ErrorCodeDef.NOT_NULL, "FlowBean"); int result = ErrorCodeDef.SUCCESS; // match flow config FlowConfig config = match(flowName); Assert.notNull(config, ErrorCodeDef.FLOW_NOT_MATCH, bean); try { execute(bean, new FlowContext(config)); } catch (Exception e) { LoggerUtil.error("flow process error.", e); FrameworkException fe = e instanceof FrameworkException ? (FrameworkException) e : new FrameworkException(e); if (throwable) { throw fe; } result = fe.getCode(); } return result; }
LoggerUtil.error(e); if (ds != null) { ds.close();