⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod11ans.lst

📁 Mcgraw-Hill - Java 2 - A Beginner S Guide, 2Nd Ed - 2003 -prog.
💻 LST
字号:
listing 1
// Make the TickTock class actually keep time. 
  
class TickTock {  
  
  synchronized void tick(boolean running) {  
    if(!running) { // stop the clock  
      notify(); // notify any waiting threads  
      return;  
    }  
  
    System.out.print("Tick ");  
 
    // wait 1/2 second 
    try { 
      Thread.sleep(500); 
    } catch(InterruptedException exc) { 
      System.out.println("Thread interrupted.");  
    } 
        
    notify(); // let tock() run  
    try {  
      wait(); // wait for tock() to complete  
    }  
    catch(InterruptedException exc) {  
      System.out.println("Thread interrupted.");  
    }  
  }  
  
  synchronized void tock(boolean running) {  
    if(!running) { // stop the clock  
      notify(); // notify any waiting threads  
      return;  
    }  
  
    System.out.println("Tock");  
 
    // wait 1/2 second 
    try { 
      Thread.sleep(500); 
    } catch(InterruptedException exc) { 
      System.out.println("Thread interrupted.");  
    } 
 
    notify(); // let tick() run  
    try {  
      wait(); // wait for tick to complete  
    }  
    catch(InterruptedException exc) {  
      System.out.println("Thread interrupted.");  
    }  
  }  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -