java¶àÏ̵߳ÄЧÂʾÍÒ»¶¨¸ßÂð£¿
ºÜ¾ÃûÉÏÀ´ÁË£¬·¢ÏÖËäÈ»×ÊÁϺÍÊé¿´µÄºÜ¶à£¬µ«ÊǺܾÃûÅöµÄ¶«Î÷»¹ÊǺÜÈÝÒ×µÍü¡£ÒÔºóÏ£ÍûÄܶà¼Ç¼°É¡£
½ñÌìÍæÁË°ÑÏ̳߳أ¬²¢¶ÔÆäÖеIJÎÊý×öÁËһЩµ÷Õû£¬²¢¼Ç¼Ôڶಢ·¢Çé¿öÏÂÏß³ÌÊý¶Ô¸÷ÖÖÇé¿öµÄ·´Ó¦¡£³ÌÐòÊÇÍøÉÏÕҵģ¬²¢×÷ÁËÉÔ΢Ð޸ġ£
javaµÄÏ̳߳ØʵÏÖ£¬ThreadPool
package net.zj.hz.yk.threadpool;
import java.util.LinkedList;
public class ThreadPool extends ThreadGroup {
private boolean isClosed = false; // Ï̳߳ØÊÇ·ñ¹Ø±Õ
private LinkedList workQueue; // ¹¤×÷¶ÓÁÐ
private static int threadPoolID = 1; // Ï̳߳صÄid
public ThreadPool(int poolSize) {
super(threadPoolID + "");// Ö¸¶¨ThreadGroupµÄÃû³Æ
setDaemon(true); // ¼Ì³Ðµ½µÄ·½·¨£¬ÉèÖÃÊÇ·ñÊØ»¤Ï̳߳Ø
workQueue = new LinkedList(); // ´´½¨¹¤×÷¶ÓÁÐ
for (int i = 0; i < poolSize; i++) {
new WorkThread(i).start(); // ´´½¨²¢Æô¶¯¹¤×÷Ïß³Ì,Ï̳߳ØÊýÁ¿ÊǶàÉپʹ´½¨¶àÉÙ¸ö¹¤×÷Ïß³Ì
}
}
/** µÈ´ý¹¤×÷Ḭ̈߳ÑËùÓÐÈÎÎñÖ´ÐÐÍê±Ï */
public void waitFinish() {
synchronized (this) {
isClosed = true;
notifyAll(); // »½ÐÑËùÓл¹ÔÚgetTask()·½·¨ÖеȴýÈÎÎñµÄ¹¤×÷Ïß³Ì
}
// activeCount() ·µ»Ø¸ÃÏß³Ì×éÖлÏ̵߳ĹÀ¼ÆÖµ¡£
Thread[] threads = new Thread[activeCount()];
// enumerate()·½·¨¼Ì³Ð×ÔThreadGroupÀ࣬¸ù¾Ý»î¶¯Ï̵߳ĹÀ¼ÆÖµ»ñµÃÏß³Ì×éÖе±Ç°ËùÓлµÄ¹¤×÷Ïß³Ì
int count = enumerate(threads);
for (int i = 0; i < count; i++) { // µÈ´ýËùÓй¤×÷Ï߳̽áÊø
try {
threads[i].join(); // µÈ´ý¹¤×÷Ï߳̽áÊø
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
/** ¹Ø±ÕÏß³Ì³Ø */
public synchronized void closePool() {
if (!isClosed) {
// µÈ´ý¹¤×÷Ïß³ÌÖ´ÐÐÍê±Ï
waitFinish();
isClosed = true;
// Çå¿Õ¹¤×÷¶ÓÁÐ
workQueue.clear();
// ÖжÏÏ̳߳ØÖеÄËùÓеŤ×÷Ïß³Ì,´Ë·½·¨¼Ì³Ð×ÔThreadGroupÀà
interrupt();
}
}
/** Ïò¹¤×÷¶ÓÁÐÖмÓÈëÒ»¸öÐÂÈÎÎñ,Óɹ¤×÷Ïß³ÌÈ¥Ö´ÐиÃÈÎÎñ */
public synchronized void execute(Runnable task) {
if (isClosed) {
throw new IllegalStateException();
}
if (task != null) {
// Ïò¶ÓÁÐÖмÓÈëÒ»¸öÈÎÎñ
Ïà¹ØÎĵµ£º
Ò»¡¢ÈçºÎ°²×°JDK£¿
µ±ÎÒÃÇ´ÓÍøÂçÉÏDOWNÏÂJ2SE 5.0 JDKÒÔºó£¨ÊÇÒ»¸ö¿ÉÖ´ÐÐÎļþ£¬ÎļþÃû½Ð×öjdk-1_5_0-windows-i586.exe£¬µ±È»Õâ¸öÃû×Ö»áÒòΪ¶ÔÓ¦²Ù×÷ϵͳµÄ²»Í¬¶øÓÐËùÇø±ðµÄ£¬ÎÒʹÓõIJÙ×÷ϵͳ¾ÍÊÇWINDOWS£¬´ó¼Ò·¢ÏÖÁËÂ𣿣©£¬Ë«»÷Ëû¾Í¿ªÊ¼°²×°ÁË¡£ÐèҪעÒâµÄ¾ÍÊÇÑ¡Ôñ°²×°Â·¾¶µÄÎÊÌâ ......
ʹÓÃJava²Ù×÷Îı¾ÎļþµÄ·½·¨Ïê½â
ÕªÒª: ×î³õjavaÊDz»Ö§³Ö¶ÔÎı¾ÎļþµÄ´¦ÀíµÄ£¬ÎªÁËÃÖ²¹Õâ¸öȱº¶¶øÒýÈëÁËReaderºÍWriterÁ½¸öÀà
×î³õjavaÊDz»Ö§³Ö¶ÔÎı¾ÎļþµÄ´¦ÀíµÄ£¬ÎªÁËÃÖ²¹Õâ¸öȱº¶¶øÒýÈëÁËReaderºÍWriterÁ½¸öÀ࣬ÕâÁ½¸öÀ඼ÊdzéÏóÀ࣬WriterÖÐ write(char[] ch,int off,int
length)£¬flush()ºÍclose()·½·¨Îª³éÏó·½· ......
CloneÕâ¸ö·½·¨ºÜ¼¦Àߣ¬ÔÒòÊÇÒòΪËüÊÇÊܱ£»¤µÄ(protected)£¬Æä¶þCloneÕâ¸ö·½·¨ÊÇ¿ÉÑ¡µÄ£¬¼´ÓпÉÄÜÀàûÓÐÌṩÕâ¸ö·½·¨¡£
cloneûÓе÷Óù¹Ô캯Êý£¬¶øÇÒÈç¹û¸¸ÀàûÓÐʵÏÖcloneµÄ»°£¬×ÓÀàÓÀÔ¶Ò²²»¿ÉÄÜÕýȷʵÏÖclone.
×ÜÖ®£¬cloneÊǸöºÜÍ·Í´µÄº¯Êý£¬Èç¹ûÒªÕýȷʵÏÖ£¬±ØÐ뿼Âǵ½É±´µÄÇé¿ö£¬·ñÔò±»¿Ë¡³öÀ´µÄ¶ÔÏó¾Í²»ÊǶÀÁ¢µÄ ......
public static void replaceString(String source,String oldStr,String newStr){
System.out.println(source);
String result = source.replaceAll("(?i)"+oldStr
, newStr); //´óСд²»Ãô ......
´úÂëÑÝʾ£º
http://code.google.com/p/finance-p/source/browse/#svn/trunk
±¾ÎÄÖ÷Òª½²½âÔÚjava»·¾³ÏÂʹÓÃjQuery½øÐÐJSONÊý¾Ý´«Ë͵Ľ»»¥¹ý³Ì
²Î¿¼¸ù¾Ý×÷ÕßµÄÕËÎñ¹ÜÀíϵͳ(¸öÈË°æ) Ô´ÂëÏÂÔØ ½²½â
Ò»¡¢Ïà¹Ø¼¼Êõ¡¢¹¤¾ß¼ò½é
1¡¢¼òµ¥½éÉÜÒ»ÏÂJSON£¬JSONÊÇÒ»ÖÖÇáÁ¿¼¶µÄÊý¾Ý½»»»¸ñʽ¡£ Ò×ÓÚÈËÔĶÁºÍ±àд¡£Í¬Ê±Ò²Ò×ÓÚ»úÆ÷½âÎöº ......