HystrixConcurrencyStrategyJsr236 extends HystrixConcurrencyStrategy { @Override public ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixProperty<Integer> corePoolSize, HystrixProperty<Integer> maximumPoolSize, HystrixProperty<Integer> keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) { ThreadFactory threadFactory = lookupManagedThreadFactory(threadPoolKey); if (threadFactory != null) { return new ThreadPoolExecutor(corePoolSize.get(), maximumPoolSize.get(), keepAliveTime.get(), unit, workQueue, threadFactory); } else { LOGGER.warn("Fallback to Hystrix default thread pool executor."); return super.getThreadPool(threadPoolKey, corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); } } HystrixConcurrencyStrategyJsr236(); @Override ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey,
                                            HystrixProperty<Integer> corePoolSize,
                                            HystrixProperty<Integer> maximumPoolSize,
                                            HystrixProperty<Integer> keepAliveTime,
                                            TimeUnit unit, BlockingQueue<Runnable> workQueue);  }
@Test public void getManagedThreadPool() throws Exception { ThreadPoolExecutor threadPool = concurrencyStrategy.getThreadPool(HystrixThreadPoolKey.Factory.asKey("test"), HystrixProperty.Factory.asProperty(10), HystrixProperty.Factory.asProperty(10), HystrixProperty.Factory.asProperty(60), TimeUnit.SECONDS, new SynchronousQueue<>()); assertThat(threadPool, is(notNullValue())); assertThat(threadPool.getThreadFactory(), is(mtf)); }
@Test public void getUnknownThreadPool() throws Exception { ThreadPoolExecutor threadPool = concurrencyStrategy.getThreadPool(HystrixThreadPoolKey.Factory.asKey("unknown"), HystrixProperty.Factory.asProperty(10), HystrixProperty.Factory.asProperty(10), HystrixProperty.Factory.asProperty(60), TimeUnit.SECONDS, new SynchronousQueue<>()); assertThat(threadPool, is(notNullValue())); assertThat(threadPool.getThreadFactory(), not(mtf)); }
@Test public void getNoManagedThreadPool() throws Exception { reset(rule.getContext()); when(rule.getContext().lookup("java:concurrent/test")).thenReturn("NoManagedThreadPool"); ThreadPoolExecutor threadPool = concurrencyStrategy.getThreadPool(HystrixThreadPoolKey.Factory.asKey("test"), HystrixProperty.Factory.asProperty(10), HystrixProperty.Factory.asProperty(10), HystrixProperty.Factory.asProperty(60), TimeUnit.SECONDS, new SynchronousQueue<>()); assertThat(threadPool, is(notNullValue())); assertThat(threadPool.getThreadFactory(), not(mtf)); }