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

📄 saver.java

📁 Java程序设计高级教程(第三版)
💻 JAVA
字号:
package examples.threads.bank;
/** 
  * A class to demonstrate wait and notify methods
  */
public class Saver implements Runnable {
   private BankAccount account;
   /** Class constructor method
     * @param ba The bank account where this saver
     *    puts the money
     */
   public Saver( BankAccount ba ) {
      account = ba;
   }
   /** The method the saver uses to put away money */
   public void run() {
      while( account.isOpen() ) {
         try {
            if ( account.deposit( 100 ) ) {
               System.out.println( 
               "$100 successfully deposited." );
            }
            Thread.currentThread().sleep( 1000 );
         } catch ( InterruptedException iex ) {
            // display the exception, but continue
            System.err.println( iex );
         }
      }
   }
}

⌨️ 快捷键说明

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