Java tutorial
//package com.java2s; /** * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ public class Main { /** * Attempt to join the thread specified safely. * * @param thread the thread to join, not null * @param timeoutMillis the timeout in milliseconds * @return true if the join succeeded, false if a timeout occurred */ public static boolean safeJoin(Thread thread, long timeoutMillis) { if (!thread.isAlive()) { return true; } try { thread.join(timeoutMillis); } catch (InterruptedException e) { // clear the interrupted state Thread.interrupted(); } return !thread.isAlive(); } }