JavaỊ̈߳ºÐÂÌØÕ÷ Ìõ¼þ±äÁ¿
JavaỊ̈߳ºÐÂÌØÕ÷-Ìõ¼þ±äÁ¿
Ìõ¼þ±äÁ¿ÊÇJava5Ïß³ÌÖкÜÖØÒªµÄÒ»¸ö¸ÅÄ¹ËÃû˼Ò壬Ìõ¼þ±äÁ¿¾ÍÊDZíʾÌõ¼þµÄÒ»ÖÖ±äÁ¿¡£µ«ÊDZØÐë˵Ã÷£¬ÕâÀïµÄÌõ¼þÊÇûÓÐʵ¼Êº¬ÒåµÄ£¬½ö½öÊǸö±ê¼Ç¶øÒÑ£¬²¢ÇÒÌõ¼þµÄº¬ÒåÍùÍùͨ¹ý´úÂëÀ´¸³ÓèÆ京Òå¡£
ÕâÀïµÄÌõ¼þºÍÆÕͨÒâÒåÉϵÄÌõ¼þ±í´ïʽÓÐ×ÅÌìÈÀÖ®±ð¡£
Ìõ¼þ±äÁ¿¶¼ÊµÏÖÁËjava.util.concurrent.locks.Condition½Ó¿Ú£¬Ìõ¼þ±äÁ¿µÄʵÀý»¯ÊÇͨ¹ýÒ»¸öLock¶ÔÏóÉϵ÷ÓÃnewCondition()·½·¨À´»ñÈ¡µÄ£¬ÕâÑù£¬Ìõ¼þ¾ÍºÍÒ»¸öËø¶ÔÏó°ó¶¨ÆðÀ´ÁË¡£Òò´Ë£¬JavaÖеÄÌõ¼þ±äÁ¿Ö»ÄܺÍËøÅäºÏʹÓã¬À´¿ØÖƲ¢·¢³ÌÐò·ÃÎʾºÕù×ÊÔ´µÄ°²È«¡£
Ìõ¼þ±äÁ¿µÄ³öÏÖÊÇΪÁ˸ü¾«Ï¸¿ØÖÆÏ̵߳ȴýÓ뻽ÐÑ£¬ÔÚJava5֮ǰ£¬Ï̵߳ĵȴýÓ뻽ÐÑÒÀ¿¿µÄÊÇObject¶ÔÏóµÄwait()ºÍnotify()/notifyAll()·½·¨£¬ÕâÑùµÄ´¦Àí²»¹»¾«Ï¸¡£
¶øÔÚJava5ÖУ¬Ò»¸öËø¿ÉÒÔÓжà¸öÌõ¼þ£¬Ã¿¸öÌõ¼þÉÏ¿ÉÒÔÓжà¸öÏ̵߳ȴý£¬Í¨¹ýµ÷ÓÃawait()·½·¨£¬¿ÉÒÔÈÃÏß³ÌÔÚ¸ÃÌõ¼þϵȴý¡£µ±µ÷ÓÃsignalAll()·½·¨£¬ÓÖ¿ÉÒÔ»½ÐѸÃÌõ¼þϵĵȴýµÄÏ̡߳£ÓйØCondition½Ó¿ÚµÄAPI¿ÉÒÔ¾ßÌå²Î¿¼JavaAPIÎĵµ¡£
Ìõ¼þ±äÁ¿±È½Ï³éÏó£¬ÔÒòÊÇËû²»ÊÇ×ÔÈ»ÓïÑÔÖеÄÌõ¼þ¸ÅÄ¶øÊdzÌÐò¿ØÖƵÄÒ»ÖÖÊֶΡ£
ÏÂÃæÒÔÒ»¸öÒøÐдæÈ¡¿îµÄÄ£Äâ³ÌÐòΪÀýÀ´½Ò¸ÇJava¶àÏß³ÌÌõ¼þ±äÁ¿µÄÉñÃØÃæÉ´£º
ÓÐÒ»¸öÕË»§£¬¶à¸öÓû§£¨Ị̈߳©ÔÚͬʱ²Ù×÷Õâ¸öÕË»§£¬ÓеĴæ¿îÓеÄÈ¡¿î£¬´æ¿îËæ±ã´æ£¬È¡¿îÓÐÏÞÖÆ£¬²»ÄÜ͸֧£¬ÈκÎÊÔͼ͸֧µÄ²Ù×÷¶¼½«µÈ´ýÀïÃæÓÐ×ã¹»´æ¿î²ÅÖ´ÐвÙ×÷¡£
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* JavaỊ̈߳ºÌõ¼þ±äÁ¿
*
* @author leizhimin 2009-11-5 10:57:29
*/
public class Test {
public static void main(String[] args) {
//´´½¨²¢·¢·ÃÎʵÄÕË»§
MyCount myCount = new MyCount("95599200901215522", 10000);
&nb
Ïà¹ØÎĵµ£º
JavaỊ̈߳ºÏß³ÌջģÐÍÓëÏ̵߳ıäÁ¿
SCJP5ѧϰ±Ê¼Ç
ÒªÀí½âÏ̵߳÷¶ÈµÄÔÀí£¬ÒÔ¼°Ïß³ÌÖ´Ðйý³Ì£¬±ØÐëÀí½âÏß³ÌջģÐÍ¡£
Ïß³ÌÕ»ÊÇָijʱ¿ÌʱÄÚ´æÖÐÏ̵߳÷¶ÈµÄÕ»ÐÅÏ¢£¬µ±Ç°µ÷Óõķ½·¨×ÜÊÇλÓÚÕ»¶¥¡£Ïß³ÌÕ»µÄÄÚÈÝÊÇËæ×ųÌÐòµÄÔËÐж¯Ì¬±ä»¯µÄ£¬Òò´ËÑо¿Ïß³ÌÕ»±ØÐëÑ¡ÔñÒ»¸öÔËÐеÄʱ¿Ì£¨Êµ¼ÊÉÏÖ¸´úÂëÔËÐе½Ê²Ã´µØ· ......
JavaỊ̈߳ºÏ̵߳Ľ»»¥
SCJP5ѧϰ±Ê¼Ç
Ï߳̽»»¥ÊDZȽϸ´ÔÓµÄÎÊÌ⣬SCJPÒªÇ󲻺ܻù´¡£º¸ø¶¨Ò»¸ö³¡¾°£¬±àд´úÂëÀ´Ç¡µ±Ê¹Óõȴý¡¢Í¨ÖªºÍ֪ͨËùÓÐÏ̡߳£
Ò»¡¢Ï߳̽»»¥µÄ»ù´¡ÖªÊ¶
SCJPËùÒªÇóµÄÏ߳̽»»¥ÖªÊ¶µãÐèÒª´Ójava.lang.ObjectµÄÀàµÄÈý¸ö·½·¨À´Ñ§Ï°£º
void notify()
......
JavaỊ̈߳ºÏ̵߳ĵ÷¶È-ÊØ»¤Ïß³Ì
ÊØ»¤Ïß³ÌÓëÆÕͨÏß³Ìд·¨ÉÏ»ù±¾Ã´É¶Çø±ð£¬µ÷ÓÃÏ̶߳ÔÏóµÄ·½·¨setDaemon(true)£¬Ôò¿ÉÒÔ½«ÆäÉèÖÃΪÊØ»¤Ï̡߳£
ÊØ»¤Ïß³ÌʹÓõÄÇé¿ö½ÏÉÙ£¬µ«²¢·ÇÎÞÓ㬾ÙÀýÀ´Ëµ£¬JVMµÄÀ¬»ø»ØÊÕ¡¢ÄÚ´æ¹ÜÀíµÈÏ̶߳¼ÊÇÊØ»¤Ï̡߳£»¹ÓоÍÊÇÔÚ×öÊý¾Ý¿âÓ¦ÓÃʱºò£¬Ê¹ÓõÄÊý¾Ý¿âÁ¬½Ó³Ø£¬Á¬½Ó³Ø±¾ÉíÒ²°üº ......
JavaỊ̈߳ºÐÂÌØÕ÷-ÐźÅÁ¿
JavaµÄÐźÅÁ¿Êµ¼ÊÉÏÊÇÒ»¸ö¹¦ÄÜÍê±ÏµÄ¼ÆÊýÆ÷£¬¶Ô¿ØÖÆÒ»¶¨×ÊÔ´µÄÏû·ÑÓë»ØÊÕÓÐןÜÖØÒªµÄÒâÒ壬ÐźÅÁ¿³£³£ÓÃÓÚ¶àÏ̵߳ĴúÂëÖУ¬²¢Äܼà¿ØÓжàÉÙÊýÄ¿µÄÏ̵߳ȴý»ñÈ¡×ÊÔ´£¬²¢ÇÒͨ¹ýÐźÅÁ¿¿ÉÒÔµÃÖª¿ÉÓÃ×ÊÔ´µÄÊýÄ¿µÈµÈ£¬ÕâÀï×ÜÊÇÔÚÇ¿µ÷“ÊýÄ¿”¶þ×Ö£¬µ«²»ÄÜÖ¸³öÀ´ÓÐÄÄЩÔڵȴý£¬ÄÄЩ×ÊÔ ......