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

📄 clerk.java

📁 JAVA的银行系统。采用java语言编写。有简单的功能
💻 JAVA
字号:
package Bank;
	//Define the Clerk 银行职员
public class Clerk implements Runnable{
	//Constructor 构造方法
    public Clerk(Bank theBank){
		this.theBank = theBank;				// 职工需要知道雇用自己的Bank对象
		inTray = null;
    }
    
	//Receive a transaction
    public void doTransaction(Transaction transaction){
    	inTray = transaction;
    }

	//The working clerk...
    public void run(){
    	while(true){
			while(inTray == null){			// No transaction waiting?  如果“文件盒”为空,则什么也不做,休眠一段时间后再循环查看另一个“文件盒”
				try{
				    Thread.sleep(150);		//Then take a break...
				}catch(InterruptedException e){
		 		    System.out.println(e);
				}
			}
			        //一个事务被记录下来后,就会调用theBank对象中的方法执行此事务,同时将inTray复位为null
			theBank.doTransaction(inTray);
			inTray = null;				//In-tray is empty
	    }
    }

	//Busy check
    public boolean isBusy(){
    	return inTray != null;			//A full in-tray means busy!
    } 

    private Bank theBank;				//The employer - an electronic marvel  当前职工所就职的银行引用
    private Transaction inTray;			//The in - tray holding a transaction 支持事务的“文件盒”
    
    /*Clerk对象实现了Runnable接口,所以是线程
	 *每个职员都有一个“文件盒”项用来容纳一个事务,“文件盒”不为null时,表示职员在正处于忙的状态
	 *职工需要知道雇用自己的Bank对象,所以创建Clerk对象时会在thBank中保存一个引用
	 *职员通过调用doTransaction()方法,可以将一个事务放到自己的“文件盒”项中
	 *程序可以调用isBusy()检查职员是否正在忙碌,如果事务正在进行中,返回true
     */
}

⌨️ 快捷键说明

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