public void join() { JoinLock currentLock = lock; // sync lock will be blocked by the thread synchronized (currentLock) { // wait in case the thread is not running yet while (!currentLock.released) { try { currentLock.wait(); } catch (InterruptedException e) { } } } }
public void run() { while (true) { synchronized (currentLock) { try { target.run(); } catch (Throwable e) { DebugLight.printStackTrace(e); } finally { target = null; debug = null; currentLock.released = true; currentLock.notifyAll(); } } if (isInterrupted() || !Thread.currentThread().isDaemon()) { break; } else { synchronized (daemon_threads) { last_active_time = SystemTime.getCurrentTime(); if (last_active_time < last_timeout_check || last_active_time - last_timeout_check > THREAD_TIMEOUT_CHECK_PERIOD) { last_timeout_check = last_active_time; while (daemon_threads.size() > 0 && daemon_threads.size() > MIN_RETAINED) { threadWrapper thread = (threadWrapper) daemon_threads.getFirst(); long thread_time = thread.last_active_time; if (last_active_time < thread_time || last_active_time - thread_time > THREAD_TIMEOUT) { daemon_threads.removeFirst(); thread.retire(); } else { break; } } } if (daemon_threads.size() >= MAX_RETAINED) { return; } daemon_threads.addLast(this); setName("AEThread2:parked[" + daemon_threads.size() + "]"); // System.out.println( "AEThread2: queue=" + daemon_threads.size() + ",creates=" + // total_creates + ",starts=" + total_starts ); } sem.reserve(); if (target == null) { break; } } } }