Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { /** * Wait on the given object for the specified number of milliseconds. * This method will return the actual amount of time that was waited. * The current thread must hold the lock on the given object. */ public static long wait(Object o, long timeout) { long start = System.currentTimeMillis(); if (Thread.holdsLock(o)) { try { o.wait(timeout); } catch (InterruptedException e) { } } return System.currentTimeMillis() - start; } /** * Wait on the given object indefinitely. This method will return false * if an error occured while waiting. The current thread must hold the * lock on the given object. */ public static boolean wait(Object o) { if (Thread.holdsLock(o)) { try { o.wait(); return true; } catch (InterruptedException e) { return false; } } return false; } }