receivenodedata.java

来自「Java多线程例子 为你提供一个JAVA多线程的实例」· Java 代码 · 共 40 行

JAVA
40
字号
/*
 * 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;

import javax.swing.JOptionPane;

public class ReceiveNodeData {

	public static void main(String[] args) throws InterruptedException{
		NodeList list = new NodeList(30);
		Utility.setNodeList( list );
		ThreadPool pool = new ThreadPool(7);
		Utility.setThreadPool( pool );
		
		Node n = list.getNode();
		NodeProcessThread t = pool.pop();
		t.setNode(n);

		t.startProcess();
			
		synchronized (list) {
			list.wait();
			NodeProcessThread.stopAll();
			StringBuffer sb = new StringBuffer();
			sb.append("所有节点处理完毕!\n");
			sb.append("节点数据总和为:");
			sb.append(list.getSumOfNodeValue());
			
			//这句模态对话框的调用似乎可以叫停应用程序里的所有线程!
			JOptionPane.showMessageDialog(null,sb);
		}
		
		System.exit(0);	
	}
}

⌨️ 快捷键说明

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