publicsynchronizedvoid wakeup(Battle b) ...{ if (isSleeping) ...{ // Wake up the thread notify(); try...{ wait(10000); }catch (InterruptedException e) ...{} } }
synchronized (this) ...{ // Notify the battle that we are now asleep. // This ends any pending wait() call in battle.runRound(). // Should not actually take place until we release the lock in wait(), below. notify(); isSleeping =true; // Notifying battle that we're asleep // Sleeping and waiting for battle to wake us up. try...{ wait(); }catch (InterruptedException e) ...{ log("Wait interrupted"); } isSleeping =false; // Notify battle thread, which is waiting in // our wakeup() call, to return. // It's quite possible, by the way, that we'll be back in sleep (above) // before the battle thread actually wakes up notify(); }
synchronized (r) ...{ try...{ log(".", false); r.getRobotThreadManager().start(); // Wait for the robot to go to sleep (take action) r.wait(waitTime);
}catch (InterruptedException e) ...{ log("Wait for "+ r +" interrupted."); } } if (!r.isSleeping()) ...{ log(""+ r.getName() +" still has not started after "+ waitTime +" ms... giving up."); }