I'm using a leaderSelector and path children cache together. During a
shutdown method, I'm getting an InterruptedException and i'm having trouble
figuring out a graceful way to handle it.
java.lang.InterruptedException
at
java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedNanos(AbstractQueuedSynchronizer.java:1038)
at
java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(AbstractQueuedSynchronizer.java:1326)
at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:282)
at
org.apache.curator.CuratorZookeeperClient.internalBlockUntilConnectedOrTimedOut(CuratorZookeeperClient.java:324)
at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:105)
at
org.apache.curator.utils.EnsurePath$InitialHelper.ensure(EnsurePath.java:140)
at org.apache.curator.utils.EnsurePath.ensure(EnsurePath.java:99)
at
org.apache.curator.framework.recipes.cache.PathChildrenCache.refresh(PathChildrenCache.java:481)
at
org.apache.curator.framework.recipes.cache.RefreshOperation.invoke(RefreshOperation.java:35)
at
org.apache.curator.framework.recipes.cache.PathChildrenCache$10.run(PathChildrenCache.java:762)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Here's my shutdown code.
if
(curatorFramework.getState().equals(CuratorFrameworkState.STARTED)) {
pathChildrenCache.close();
leaderSelector.close();
curatorFramework.close();
}
I'm assuming the closing of PathChildrenCache and LeaderSelector are
probably asynchronous? Adding Thread.sleep(2000); does not seem to help,
though. Is there an excepted way of closing these and waiting?