@Override public void run() { try { process(event); } catch (Throwable e) { log.error("{} Failed to process event {}", getName(), event, e); } } });
@Override public void run() { try { process(event); } catch (Throwable e) { log.error("{} Failed to process event {}", getName(), event, e); } } });
/** * Create an asynchronous event listener which uses a thread poool to process events. * * @param poolSize size of the event processing pool * @param timeOutSeconds time out in seconds when an idle thread is destroyed * @param isDaemon if the threads used to process should be daemon threads, * if false, then implementation should call stop() * to stop the thread pool */ public AsyncEventListener(int poolSize, long timeOutSeconds, final boolean isDaemon) { eventQueue = new LinkedBlockingQueue<>(); ThreadFactory factory = new BasicThreadFactory.Builder() .namingPattern(getName()+"_AsyncThread-%d") .daemon(isDaemon) .priority(Thread.NORM_PRIORITY) .build(); // fixed pool with min and max equal to poolSize processor = new ThreadPoolExecutor(poolSize, poolSize, timeOutSeconds, TimeUnit.SECONDS, eventQueue, factory); processor.allowCoreThreadTimeOut(true); }
/** * Create an asynchronous event listener which uses a thread poool to process events. * * @param poolSize size of the event processing pool * @param timeOutSeconds time out in seconds when an idle thread is destroyed * @param isDaemon if the threads used to process should be daemon threads, * if false, then implementation should call stop() * to stop the thread pool */ public AsyncEventListener(int poolSize, long timeOutSeconds, final boolean isDaemon) { eventQueue = new LinkedBlockingQueue<>(); ThreadFactory factory = new BasicThreadFactory.Builder() .namingPattern(getName()+"_AsyncThread-%d") .daemon(isDaemon) .priority(Thread.NORM_PRIORITY) .build(); // fixed pool with min and max equal to poolSize processor = new ThreadPoolExecutor(poolSize, poolSize, timeOutSeconds, TimeUnit.SECONDS, eventQueue, factory); processor.allowCoreThreadTimeOut(true); }