javaÏ̳߳Ø
Ï̳߳ØÖ÷ÒªÊÇÓÃÀ´ ´¦Àí¶à¸öÇëÇóʱ£¬¼õÉÙ×ÊÔ´ÏûºÄ£¬Ìá¸ßÓ¦ÓÃÐÔÄÜ¡£
ÏÂÃæµÄ´úÂëÊÇÀ´×ÔÓÚ ËïÎÀÇÙ£º<<JavaÍøÂç±à³Ì¾«½â>> ÖÐÏ̳߳ØʵÏÖÔ´Âë, ´úÂë½á¹¹¼òµ¥ÇåÎú£¬¶ÔÓÚÀí½âÏ̳߳أ¬wait(),notify()·½·¨¶¼ÓÐÓкܺõİïÖú.
import java.util.LinkedList;
public class ThreadPool extends ThreadGroup {
private boolean isClosed = false; // Ï̳߳ØÊÇ·ñ¹Ø±Õ
private LinkedList<Runnable> workQueue; // ±íʾ¹¤×÷¶ÓÁÐ
private static int threadPoolID; // ±íʾÏ̳߳ØID
private int threadID; // ±íʾ¹¤×÷Ïß³ÌID
public ThreadPool(int poolSize) { // poolSizeÖ¸¶¨Ï̳߳ØÖеŤ×÷Ïß³ÌÊýÄ¿
super("ThreadPool-" + (threadPoolID++));
setDaemon(true);
workQueue = new LinkedList<Runnable>(); // ´´½¨¹¤×÷¶ÓÁÐ
for (int i = 0; i < poolSize; i++)
new WorkThread().start(); // ´´½¨²¢Æô¶¯¹¤×÷Ïß³Ì
}
/** Ïò¹¤×÷¶ÓÁÐÖмÓÈëÒ»¸öÐÂÈÎÎñ£¬Óɹ¤×÷Ïß³ÌÈ¥Ö´ÐиÃÈÎÎñ */
public synchronized void execute(Runnable task) {
if (isClosed) { // Ï̳߳ر»¹ØÔòÅ׳öIllegalStateExceptionÒì³£
throw new IllegalStateException();
}
if (task != null) {
workQueue.add(task);
notify(); // »½ÐÑÕýÔÚgetTask()·½·¨ÖеȴýÈÎÎñµÄ¹¤×÷Ïß³Ì
}
}
/** ´Ó¹¤×÷¶ÓÁÐÖÐÈ¡³öÒ»¸öÈÎÎñ£¬¹¤×÷Ï̻߳áµ÷Óô˷½·¨ */
protected synchronized Runnable getTask() throws InterruptedException {
while (workQueue.size() == 0) {
if (isClosed) {
return null;
}
wait(); // Èç¹û¹¤×÷¶ÓÁÐÖÐûÓÐÈÎÎñ£¬¾ÍµÈ´ýÈÎÎñ
}
return workQueue.removeFirst();
}
/** ¹Ø±ÕÏß³Ì³Ø */
public synchronized void close() {
if (!isClosed) {
isClosed = true;
workQueue.clear();
interrupt();
}
}
/** µÈ´ý¹¤×÷Ḭ̈߳ÑËùÓÐÈÎÎñÖ´ÐÐÍê */
public void join() {
synchronized (this) {
isClosed = true;
notifyAll(); // »½ÐÑ»¹ÔÚgetTask()·½·¨ÖеȴýÈÎÎñµÄ¹¤×÷Ïß³Ì
}
Thread[] threads = new Thread[activeCount()];
// enumerate()·½·¨¼Ì³Ð×ÔThreadGroupÀ࣬»ñµÃÏß
Ïà¹ØÎĵµ£º
ÔÌûµØÖ·£ºhttp://www.hengxinsoft.com/2009/07/ubuntu%E4%B8%8Bjava%E7%8E%AF%E5%A2%83%E7%9A%84%E6%90%AD%E5%BB%BA/
°²×°
´ò¿ªÖնˣºÊäÈëÃüÁî:
sudo apt-get install sun-java6-jdk
Ìáʾ£º°²×°¹ý³ÌÖÐÐèÒªÄã»Ø´ðÊÇ·ñͬÒâʹÓÃÐÒ飨ÖÕ¶ËÖкìÀ¶É«µÄÌáʾ½çÃ棩£¬´Ëʱ°´tab¼üÖÁOK£¬ÔÙ°´»Ø³µ¼´¿ÉÕý³£°²×°
´ý°²×°Íê±ÏºóÑ¡Ôñ ......
package Demo;
// Java·ºÐÍÊý×é
public class GenericsDemo30 {
public static void main(String args[]) {
Integer i[] = fun1(1, 2, 3, 4, 5, 6); // ·µ»Ø·ºÐÍÊý×é
fun2(i);
}
public static <T> T[] fun1(T... arg) { // ½ÓÊտɱä²ÎÊý
return arg; // ·µ»Ø·ºÐÍÊý×é
}
public static <T> ......
package Demo;
// Java·ºÐͽӿÚ
interface Info24<T> { // ÔÚ½Ó¿ÚÉ϶¨Òå·ºÐÍ
public T getVar(); // ¶¨Òå³éÏó·½·¨£¬³éÏó·½·¨µÄ·µ»ØÖµ¾ÍÊÇ·ºÐÍÀàÐÍ
}
class InfoImp24<T> implements Info24<T> { // ¶¨Òå·ºÐͽӿڵÄ×ÓÀà
private T var; // ¶¨ÒåÊôÐÔ
public InfoImp24(T var) { // ͨ¹ý¹¹Ôì·½·¨É ......
µ¼ÈëÅäÖÃjar°ü substance.jar
È»ºóÔÚframeµÄÖ÷º¯Êý ¼ÓÈëÈçÏ´úÂë
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try {
UIManager.setLookAndFeel(new org.jvnet.substance.skin.SubstanceModerateLookAndFeel()) ; ......
·´ÉäµÄ»ùʯ——ClassÀà
Java³ÌÐòÖеĸ÷¸öJavaÀàÊôÓÚͬһÀàÊÂÎÃèÊöÕâÀàÊÂÎïµÄJavaÀàÃû¾ÍÊÇClass¡£±ÈÈ磺ÖÚ¶àµÄÈË¿ÉÒÔÓÃÒ»¸öPersonÀàÀ´±íʾ£¬¶øÕâ¸öÀà¾Í¿ÉÒÔÃèÊöÈ˵ÄÐÅÏ¢(ÐÕÃû¡¢ÄêÁä¡¢ÐÔ±ðµÈµÈ)£¬¶øÖÚ¶àµÄJavaÀà¾Í¿ÉÒÔÓÃClassÀ´±íʾ¡£
Question£ºPersonÀà´ú±íÈË£¬ËüµÄʵÀý¶ÔÏó¿ÉÒÔÊÇÕÅÈý¡¢ÀîËÄ£¬ ......