001/**
002 * Copyright 2010-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.common.util.base;
017
018import java.util.List;
019
020public class Threads {
021
022        /**
023         * Sleep for <code>millis</code>
024         * 
025         * @throws <code>IllegalStateException</code> if we get interrupted.
026         */
027        public static void sleep(long millis) {
028                try {
029                        Thread.sleep(millis);
030                } catch (InterruptedException e) {
031                        throw Exceptions.illegalState(e);
032                }
033        }
034
035        /**
036         * Start each thread
037         */
038        public static void start(List<Thread> threads) {
039                for (Thread thread : threads) {
040                        thread.start();
041                }
042        }
043
044        /**
045         * Invoke join() on each thread
046         * 
047         * @throws <code>IllegalStateException</code> if any thread gets interrupted.
048         */
049        public static void join(List<Thread> threads) {
050                for (Thread thread : threads) {
051                        try {
052                                thread.join();
053                        } catch (InterruptedException e) {
054                                throw Exceptions.illegalState(e, "unexpected thread interruption [id:%s] [name:%s]", thread.getId(), thread.getName());
055                        }
056                }
057        }
058}