新建 文本文档.txt

来自「模拟通道的通信过程」· 文本 代码 · 共 95 行

TXT
95
字号
package channel;

public class ChannelManager implements Runnable{
	
	private static final int NONE=0;
	
	private static final int INIT=1; 

	private static final int FINISH=2;
	
	private int interrupt=NONE;
	
	private Device device=new Device();
	
	private char[][] memory={{'l','o','v','e',' ', ' ', ' ',' ',' ', ' ',' ',' '},{'c','h','a','n','n','e','l',' ',' ',' ',' ',' '},{'a','r','c','h','i','t','e','c','t','u','r','e'}};

	public ChannelManager(int interrupt){
		this.interrupt=interrupt;
	}
	public void run() {
		while(true){
			if(this.interrupt==NONE){
				System.out.println("The cpu is doing some thing...");
				System.out.println("The cpu is doing some thing...");
				interrupt=INIT;
//				break;
			}
			if(this.interrupt==INIT){
				System.out.println("CPU is interrupt");
				System.out.println("This is I/O Init instruction,The channalManager is init the device...");
				device.memoryToDevice(memory);
				interrupt=FINISH;
//				break;
			}
			if(this.interrupt==FINISH){
				System.out.println("CPU is interrupt");
				System.out.println("This is I/O Finish instruction,The channalManager is close the device...");
				break;
			}
		}
		
	}

	public int getInterrupt() {
		return interrupt;
	}

	public void setInterrupt(int interrupt) {
		this.interrupt = interrupt;
	}
	
}
package channel;

public class Device {
	//设备存放字节的数组的长度
	private int Maxdevcap=12;
	//可用设备的个数
	private static final int ACTDEVICENUM=3;
	//
	private int actCap=30;
	
	private char[] data=new char[30];
	
	private static Device devices[] =new Device[ACTDEVICENUM];
	
	static{
		for(int i=0;i<devices.length;i++){
			devices[i]=new Device();
		}
	}
	public void memoryToDevice(char[][] memory){
		for(int i=0;i<Maxdevcap;i++){
			for(int j=0;j<ACTDEVICENUM;j++){
				if(i<devices[j].actCap){
					devices[j].data[i]=memory[j][i];
					System.out.println("设备"+j+":内容:"+memory[j][i]);
				}
			}
		}
	}
}
package channel;

public class Run {
	ChannelManager channelManager=new ChannelManager(0);
	public void show(){
		Thread thread=new Thread(channelManager);
		thread.start();
	}
	public static void main(String[] args){
		new Run().show();
	}
}

⌨️ 快捷键说明

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