@Override public Confirmation begin(MessageContext context, Message message) { final Flow flow = flows.computeIfAbsent(message.getShard(), shard -> { final Flow newFlow = new Flow(firingStrategyFactory, Flow.class.getSimpleName() + "-shard-[" + shard + "]"); synchronized (terminateLock) { createdFlows.add(newFlow); if (terminated) { // the container was already terminated -- terminate the newly created flow; the resulting Confirmation // objects won't do anything newFlow.terminate(); } } return newFlow; }); final MessageId messageId = message.getMessageId(); return flow.begin(messageId, new ConfirmTask(context, messageId)); }