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

📄 banking.java

📁 Java程序设计高级教程(第三版)
💻 JAVA
字号:
package examples.threads.bank;

/** 
  * A class to demonstrate wait and notify methods
  */
public class Banking {
   /** The test method for the class
     * @param args[0] Time in seconds for which
     *    this banking process should run
     */
   public static void main( String[] args ) {
      BankAccount ba = new BankAccount();

      // create the spender thread
      Spender spenderThread = new Spender( ba );

      // create the saver thread which is a two-step
      // process because Saver implements Runnable
      Saver aSaver = new Saver( ba );
      Thread saverThread = new Thread( aSaver );

      spenderThread.start();
      saverThread.start();

      int time;
      if ( args.length == 0 ) {
         time = 10000;
      } else {
         time = Integer.parseInt( args[0] ) * 1000;
      }
         
      try {
         Thread.currentThread().sleep( time );
      } catch ( InterruptedException iex ) {
         /* ignore it */
      }
      // close the bank account
      ba.close();      
   }
}

⌨️ 快捷键说明

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