@Override public void execute(Runnable command) { final int size = tasks.size(); if (size == WARNING_THRESHOLD) { log.warn( "User thread has {} pending tasks, memory exhaustion may occur.\n" + "If you see this message, check your memory consumption and see if it's problematic or excessively spikey.\n" + "If it is, check for deadlocked or slow event handlers. If it isn't, try adjusting the constant \n" + "Threading.UserThread.WARNING_THRESHOLD upwards until it's a suitable level for your app, or Integer.MAX_VALUE to disable.", size); } Uninterruptibles.putUninterruptibly(tasks, command); }
public synchronized String nanny(UbaCoordinate ubaCoordinate) throws InterruptedException, ExecutionException { long now = System.currentTimeMillis(); if (restartAtTimestamp.get() > 0 && restartAtTimestamp.get() < now) { status.set("Restarting"); deployLog.log("Nanny", "restart triggered by timestamp. " + this, null); if (kill()) { lastRestart.set(now); restartAtTimestamp.set(-1); } } try { if (destroyed.get()) { status.set("Destroying"); deployLog.log("Nanny", "tried to check a service that has been destroyed. " + this, null); return deployLog.getState(); } if (linkedBlockingQueue.size() == 0) { try { if (redeploy.get()) { status.set("Redeploy"); NannyDestroyCallable destroyTask = new NannyDestroyCallable( instanceDescriptor.get(), instancePath, deployLog, healthLog, invokeScript, ubaLog); deployLog.log("Nanny", "destroying in preperation to redeploy. " + this, null); Future<Boolean> destroyFuture = threadPoolExecutor.submit(destroyTask); status.set("Destroying"); if (destroyFuture.get()) { NannyDeployCallable deployTask = new NannyDeployCallable( repositoryProvider, ubaCoordinate, instanceDescriptor.get(), instancePath, deployLog, healthLog, deployableValidator, invokeScript, ubaLog); deployLog.log("Nanny", "redeploying. " + this, null); Future<Boolean> deployedFuture = threadPoolExecutor.submit(deployTask); try { status.set("Deploying"); if (deployedFuture.get()) { try { try (FileWriter writer = new FileWriter(instancePath.deployLog())) { for (String line : deployLog.peek()) { writer.write(line); } } redeploy.set(false); status.set("Redeployed"); deployLog.log("Nanny", "successfully redeployed. " + this, null); } catch (Exception x) { status.set("Failed redeployed"); deployLog.log("Nanny", "failed to redeployed. " + this, x); } } } catch (ExecutionException ee) { status.set("Unexpected state"); deployLog.log("Nanny", "encountered an unexpected condition. " + this, ee); } } } NannyStatusCallable nannyTask = new NannyStatusCallable( this, status, startupTimestamp, instanceDescriptor.get(), instancePath, deployLog, healthLog, invokeScript, ubaLog, haveRunConfigExtractionCache); if (nannyTask.callable()) { threadPoolExecutor.submit(nannyTask); } else { deployLog.log("Nanny", "skipped status check. " + this, null); } } catch (InterruptedException | ExecutionException x) { deployLog.log("Nanny", "is already running. " + this, x); } return deployLog.getState(); } else { return deployLog.getState(); } } finally { deployLog.commit(); } }