Java Map Join join(final long timeout, final Map throwableMap, final Thread... threads)

Here you can find the source of join(final long timeout, final Map throwableMap, final Thread... threads)

Description

Wait on each thread, individually, for timeout milliseconds.

License

Apache License

Parameter

Parameter Description
timeout a parameter
throwableMap a parameter
threads a parameter

Declaration

public static void join(final long timeout, final Map<Thread, Throwable> throwableMap,
        final Thread... threads) 

Method Source Code

//package com.java2s;
/**//from w w w  . j  a va 2s  .  c  o m
 * Copyright 2012 Akiban Technologies, Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.Map;

public class Main {
    /**
     * Wait on each thread, individually, for <code>timeout</code> milliseconds.
     * The {@link Thread#join(long)} method is used for this (<code>0</code>
     * means indefinite). Add an Exception to the error map for any thread that
     * did not end within its timeout.
     * 
     * @param timeout
     * @param throwableMap
     * @param threads
     */
    public static void join(final long timeout, final Map<Thread, Throwable> throwableMap,
            final Thread... threads) {
        for (final Thread t : threads) {
            Throwable error = null;
            try {
                t.join(timeout);
                if (t.isAlive()) {
                    error = new AssertionError("Thread did not complete in timeout: " + timeout);
                }
            } catch (final InterruptedException e) {
                error = e;
            }
            if (error != null) {
                throwableMap.put(t, error);
            }
        }
    }
}

Related

  1. join(final Map map1, final Map map2, final Map... maps)
  2. join(final Map add, final Map... imports)
  3. join(List> list)
  4. Join(Map map, String entryGlue, String elementGlue)