private void exportChildren(final ExportTransaction transaction) throws CommandException { final int timeOutFactor = 40; final CnATreeElement element = transaction.getElement(); final Set<CnATreeElement> children = element.getChildren(); if (FinishedRiskAnalysis.TYPE_ID.equals(element.getTypeId())) { children.addAll(getRiskAnalysisOrphanElements(element)); } final List<ExportTransaction> transactionList = new ArrayList<ExportTransaction>(); taskExecutor = Executors.newFixedThreadPool(getMaxNumberOfThreads()); if (!children.isEmpty()) { for (final CnATreeElement child : children) { final ExportTransaction childTransaction = new ExportTransaction(child); transactionList.add(childTransaction); final ExportThread thread = new ExportThread(childTransaction); configureThread(thread); // Multi thread: thread.addListener( new IThreadCompleteListener() { @Override public void notifyOfThreadComplete(final Thread thread) { final ExportThread exportThread = (ExportThread) thread; synchronized (LOCK) { if (exportThread.getSyncObject() != null) { transaction.getTarget().getChildren().add(exportThread.getSyncObject()); } getValuesFromThread(exportThread); } } }); taskExecutor.execute(thread); } } awaitTermination(transactionList.size() * timeOutFactor); if (getLog().isDebugEnabled() && transactionList.size() > 0) { getLog().debug(transactionList.size() + " export threads finished."); } for (final ExportTransaction childTransaction : transactionList) { if (checkElement(childTransaction.getElement())) { exportChildren(childTransaction); } } }