public void run() throws InterruptedException, IOException { try { while (flows.isEmpty() == false) { boolean submitted = submit(); if (submitted == false) { if (running.isEmpty()) { throw new IOException( MessageFormat.format("Deadlock was detected in \"{0}\": {1}", batchId, blocking)); } waitForComplete(); } } while (running.isEmpty() == false) { waitForComplete(); } } finally { YSLOG.info("I01004", batchId); for (FlowScriptTask task : running.values()) { task.cancel(true); } while (running.isEmpty() == false) { try { waitForComplete(); } catch (IOException e) { YSLOG.warn(e, "W01002", batchId); } } } }