private boolean tryResize(int depth) throws PoolResourceException { // NOTE: let's prevent stack overflow when pool resizing is not sufficient and thread gets stuck doing recursive calls, either: // * application is in bad shape already or // * initialPoolSize is insufficient and/or ResizePolicy is not configured properly if (depth > MAX_RESIZE_INTERNAL_STACK_DEPTH) { // this will not get anywhere.. throwing to resurface throw new PoolResourceException( String.format("ResizePolicy is ineffective. Pool %s has to be reconfigured to handle current load.", poolName)); } // let's allow only one thread to get in if (resizing.compareAndSet(false, true)) { this.countDownLatch.set(new CountDownLatch(1)); return resize(result -> { this.countDownLatch.get().countDown(); resizing.set(false); }); } try { countDownLatch.get().await(resizeTimeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e1) { throw new IllegalStateException("Thread interrupted while waiting for resizing to complete"); } return false; }
private boolean tryResize(int depth) throws PoolResourceException { // NOTE: let's prevent stack overflow when pool resizing is not sufficient and thread gets stuck doing recursive calls, either: // * application is in bad shape already or // * initialPoolSize is insufficient and/or ResizePolicy is not configured properly if (depth > MAX_RESIZE_INTERNAL_STACK_DEPTH) { // this will not get anywhere.. throwing to resurface throw new PoolResourceException( String.format("ResizePolicy is ineffective. Pool %s has to be reconfigured to handle current load.", poolName)); } // let's allow only one thread to get in if (resizing.compareAndSet(false, true)) { this.countDownLatch.set(new CountDownLatch(1)); return resize(result -> { this.countDownLatch.get().countDown(); resizing.set(false); }); } try { countDownLatch.get().await(resizeTimeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e1) { throw new IllegalStateException("Thread interrupted while waiting for resizing to complete"); } return false; }