Here you can find the source of join(final long timeout, final Map
timeout
milliseconds.
Parameter | Description |
---|---|
timeout | a parameter |
throwableMap | a parameter |
threads | a parameter |
public static void join(final long timeout, final Map<Thread, Throwable> throwableMap, final Thread... threads)
//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); } } } }