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

📄 node.java

📁 Java多线程例子 为你提供一个JAVA多线程的实例
💻 JAVA
字号:
/*
 * Created on 2005-9-2
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.apollo.thread.example;

public class Node {
	
	private int id = 0;
	private int data = -1;
	private byte state = Node.RECEIVE_READY;
	
	public static byte RECEIVE_READY = 0;		//准备接收数据
	public static byte RECEIVE_MIDMAY = 1;		//接收数据中
	public static byte RECEIVE_COMPLETE = 2;	//数据接收完成
	
	public void setState(byte state){
		this.state = state;
	}

	public Node(int id) {
		this.id = id;
	}
	
	public String toString(){
		return "Node_"+Integer.toString(id);
	}
	
	public boolean isReady(){
		return state == Node.RECEIVE_READY;
	}
	
	public boolean isReceiving(){
		return state == Node.RECEIVE_MIDMAY;
	}
	
	public boolean isComplete(){
		return state == Node.RECEIVE_COMPLETE;
	}
	
	public int getData(){
		return data;
	}
	
	public void receiveData() throws InterruptedException{
		data = (int) (Math.random()*10+1);
		new NodeFrame(this);
		synchronized (this) {
				this.wait();
		}
		System.out.println(this+"接受数据完毕!");
	}

}

⌨️ 快捷键说明

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