Java Concurrent°üѧϰ֮BlockingQueue
BlockingQueueÊÇÒ»¸ö½Ó¿Ú£¬Ëü´ÓQueue¼Ì³Ð¶øÀ´£¬
°üº¬ÁËQueueµÄËùÓй¦ÄÜ£¬²¢ÔÚQueueµÄ»ù´¡ÉÏÌṩÁË2¸öÐµĹ¦ÄÜ£º
1. ¼ìË÷ÔªËØʱµÈ´ý¶ÓÁбäΪ·Ç¿Õ
2. ´æ´¢ÔªËØʱµÈ´ý¿Õ¼ä±äµÃ¿ÉÓá£
ÏÂÃæ³Â¼Ò»Ð©JDKÎĵµÖйØÓÚBlockingQueueµÄ½éÉÜ£º
BlockingQueue ¿ÉÒÔÊÇÏÞ¶¨ÈÝÁ¿µÄ¡£ËüÔÚÈÎÒâ¸ø¶¨Ê±¼ä¶¼¿ÉÒÔÓÐÒ»¸ö remainingCapacity£¬³¬³ö´ËÈÝÁ¿£¬±ãÎÞ·¨ÎÞ×èÈûµØ put ¶îÍâµÄÔªËØ¡£Ã»ÓÐÈκÎÄÚ²¿ÈÝÁ¿Ô¼ÊøµÄ BlockingQueue ×ÜÊDZ¨¸æ Integer.MAX_VALUE µÄÊ£ÓàÈÝÁ¿¡£
BlockingQueue ʵÏÖÖ÷ÒªÓÃÓÚÉú²úÕß-ʹÓÃÕ߶ÓÁУ¬µ«ËüÁíÍ⻹֧³Ö Collection ½Ó¿Ú¡£Òò´Ë£¬¾ÙÀýÀ´Ëµ£¬Ê¹Óà remove(x) ´Ó¶ÓÁÐÖÐÒƳýÈÎÒâÒ»¸öÔªËØÊÇÓпÉÄܵġ£È»¶ø£¬ÕâÖÖ²Ù×÷ͨ³£²» »áÓÐЧִÐУ¬Ö»ÄÜÓмƻ®µØż¶ûʹÓ㬱ÈÈçÔÚÈ¡ÏûÅŶÓÐÅϢʱ¡£
BlockingQueue ʵÏÖÊÇḬ̈߳²È«µÄ¡£ËùÓÐÅŶӷ½·¨¶¼¿ÉÒÔʹÓÃÄÚ²¿Ëø¶¨»òÆäËûÐÎʽµÄ²¢·¢¿ØÖÆÀ´×Ô¶¯´ïµ½ËüÃǵÄÄ¿µÄ¡£È»¶ø£¬´óÁ¿µÄ Collection ²Ù×÷£¨addAll¡¢containsAll¡¢retainAll ºÍ removeAll£©Ã»ÓÐ ±ØÒª×Ô¶¯Ö´ÐУ¬³ý·ÇÔÚʵÏÖÖÐÌرð˵Ã÷¡£Òò´Ë£¬¾ÙÀýÀ´Ëµ£¬ÔÚÖ»Ìí¼ÓÁË c ÖеÄһЩԪËغó£¬addAll(c) ÓпÉÄÜʧ°Ü£¨Å׳öÒ»¸öÒì³££©¡£
BlockingQueue ʵÖÊÉϲ» Ö§³ÖʹÓÃÈκÎÒ»ÖÖ“close”»ò“shutdown”²Ù×÷À´Ö¸Ê¾²»ÔÙÌí¼ÓÈκÎÏî¡£ÕâÖÖ¹¦ÄܵÄÐèÇóºÍʹÓÃÓÐÒÀÀµÓÚʵÏÖµÄÇãÏò¡£ÀýÈ磬һÖÖ³£ÓõIJßÂÔÊÇ£º¶ÔÓÚÉú²úÕߣ¬²åÈëÌØÊâµÄ end-of-stream »ò poison ¶ÔÏ󣬲¢¸ù¾ÝʹÓÃÕß»ñÈ¡ÕâЩ¶ÔÏóµÄʱ¼äÀ´¶ÔËüÃǽøÐнâÊÍ¡£
ÔÚJDK1.5ÖÐÌṩÁËBlockingQueueµÄÈçÏÂʵÏÖÀࣺ
1. ArrayBlockingQueue
2. LinkedBlockingQueue
3. PriorityBlockingQueue
4. SynchronousQueue
5. DelayQueue
ÏÂÃæÎÒÃÇÀ´Ò»Ò»½éÉÜÕâЩBolackingQueueʵÏÖµÄÌص㣺
1. ArrayBlockingQueue
¹ÊÃû˼Ò⣬ArrayBlockingQueueÊÇÒ»¸öÓÉÊý×éÖ§³ÖµÄÓнç×èÈû¶ÓÁС£´Ë¶ÓÁа´ FIFO£¨ÏȽøÏȳö£©ÔÔò¶ÔÔªËؽøÐÐÅÅÐò¡£¶ÓÁеÄÍ·²¿ ÊÇÔÚ¶ÓÁÐÖдæÔÚʱ¼ä×µÄÔªËØ¡£¶ÓÁеÄβ²¿ ÊÇÔÚ¶ÓÁÐÖдæÔÚʱ¼ä×î¶ÌµÄÔªËØ¡£ÐÂÔªËزåÈëµ½¶ÓÁеÄβ²¿£¬¶ÓÁмìË÷²Ù×÷ÔòÊÇ´Ó¶ÓÁÐÍ·²¿¿ªÊ¼»ñµÃÔªËØ¡£
ÕâÊÇÒ»¸öµäÐ͵ēÓн绺´æÇø”£¬¹Ì¶¨´óСµÄÊý×éÔÚÆäÖб£³ÖÉú²úÕß²åÈëµÄÔªËغÍʹÓÃÕßÌáÈ¡µÄÔªËØ¡£Ò»µ©´´½¨ÁËÕâÑùµÄ»º´æÇø£¬¾Í²»ÄÜÔÙÔö¼ÓÆäÈÝÁ¿¡£ÊÔͼÏòÒÑÂú¶ÓÁÐÖзÅÈëÔªËػᵼÖ·ÅÈë²Ù×÷ÊÜ×èÈû£»ÊÔͼ´Ó¿Õ¶ÓÁÐÖмìË÷ÔªËؽ«µ¼ÖÂÀàËÆ×èÈû¡£
´ËÀàÖ§³Ö¶ÔµÈ´ýµ
Ïà¹ØÎĵµ£º
¸ö ÈË ¼ò Àú
ÐÕ Ãû£º
ÍõÖ¾¹ú
ÐÔ ±ð£º
ÄÐ
Äê Á䣺
23Ëê
ÁªÏµµç»°£º
13124799190
ר Òµ£º
¼ÆËã»ú¼¼Êõ
¹¤×÷ʱ¼ä£º
Ò»ÄêÒÔÉÏ
ѧ Àú£º
´óר
ÓÊ Ï䣺
andy478168@yeah.net
¡ï ÇóÖ°ÒâÏò
¹¤×÷ÐÔÖÊ ......
Ö÷ÒªÊÇ×ö¸÷µØÒøÐеÄÍâΧϵͳ£¬ÀýÈçµç×Ó»ãƱ¡¢·´Ï´Ç®ÏµÍ³µÈ£¬ÓÐÐËȤµÄ¿ÉÒÔ¼ÓÎÒQQ£¨429177125£©¾ßÌåÁÄ£¬ÃæÊԵصãÔÚ±±¾©Êк£µíÇøκ¹«´å¡£
¾ßÌåÈçÏ£º
Java¹¤×÷¾Ñ飬2-3Äê
ÈíÐÔÒªÇó£º ÒÔϹ¤×÷¾ÑéÖ®Ò»ÕßÓÅÏÈ¡£1¡¢ ÓÐÒøÐй¤×÷¾ ......
±¾ÎÄÕª×Ô£º http://www.ibm.com/developerworks/cn/java/j-noaccent.html
ѧϰһÖÖеıà³ÌÓïÑÔ±ÈѧϰеĿÚÍ·ÓïÑÔÒªÈÝÒ׵öࡣȻ¶ø£¬ÔÚÕâÁ½ÖÖѧϰ¹ý³ÌÖУ¬¶¼Òª¸¶³ö¶îÍâµÄŬÁ¦È¥Ñ§Ï°²»´ø¿ÚÒôµØ˵ÐÂÓïÑÔ¡£Èç¹ûÄúÊìϤ C »ò C++£¬ÄÇôѧϰ Java ÓïÑÔ²¢²»À§ÄÑ£¬Õâ¾ÍÏñÊÇ»á˵ÈðµäÓïµÄÈËȥѧµ¤ÂóÓïÒ»Ñù¡£ÓïÑÔËäÓв»Í¬£¬µ«Óֱ˴˻ ......
public static void main(string[] args)
{
int[] arrayInt=new int[] {1,2,3,4,5}
ArrayList alist =ArrayList();
//·½·¨Ò»
foreach(int i in alist)
{
&nbs ......
±à¼¹¤³ÌµÄ.projectÎļþ£º
Ìí¼Ó
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
µ½
<natures>
…
& ......