saver.java

来自「北京大学出版社的」· Java 代码 · 共 32 行

JAVA
32
字号
package examples.threads;

/** 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 + =
减小字号Ctrl + -
显示快捷键?