void startServices() { try { Throwable firstError = null; List<ServiceThread> threads = new ArrayList<ServiceThread>(); if (LOG.isDebugEnabled()) { LOG.debug("Begin parallel start"); } for (ServiceWithDependency sd : services.values()) { // start the service. If this fails that service // will be stopped and an exception raised ServiceThread st = new ServiceThread(sd); threads.add(st); } for (ServiceThread st : threads) { st.start(); } for (ServiceThread st : threads) { if (LOG.isDebugEnabled()) { LOG.debug("Waiting for service thread to join for " + st.getName()); } st.join(); if (st.error != null && firstError == null) { firstError = st.error; } } if (firstError != null) { throw ServiceStateException.convert(firstError); } if (LOG.isDebugEnabled()) { LOG.debug("End parallel start"); } } catch (InterruptedException e) { e.printStackTrace(); } }