PDF
Wait/Notify1Java(1)Contents(Synchronization)(Monitor) ..................................................... 1Wait/Notify ............................................................................................ 1线 ....................................................................................... 3Sleep / Yield ........................................................................................... 3Context switching .................................................................................... 3线线Threadstart()线线线线(Synchronization)(Monitor)线synchronized使Monitor线lockunlockmonitor线java.lang.Objectwaitnotifysynchronized使this使ClassWait/Notify线Object.wait()Object.nofity()Object.nofityAll()线线Waitwait使线线notifynotifyAll线wait线 Wait/Notify2线waitsynchronized (obj) { while (<condition does not hold>) obj.wait(); // Perform action appropriate to condition}Notifynotify线线线notifynotifyAll线线InterruptionThread.interrupt线线InterruptedException线Thread.sleep()Thread.join()Object.wait()线InterruptedExceptioninterruptedinterruptedtrue线Thread.interruptedtrueInterruptedException退线线m.notify线退线InterruptedException退线线线InterruptedException线interrupted使 Context switching3try { while (true) { Task task = queue.take(10, TimeUnit.SECONDS); task.execute(); }}catch (InterruptedException e) { Thread.currentThread().interrupt();}线线线线线线线线线退Sleep / Yield线sleep线线yield线使Context switching线线线线线线 Context switching4

HTML view coming soon.

Download PDF for the full formatted version.