JavaÏß³ÌÖ® InterruptedException Òì³£
µ±Ò»¸ö·½·¨ºóÃæÉùÃ÷¿ÉÄÜ»áÅ׳öInterruptedException Ò쳣ʱ£¬ËµÃ÷¸Ã·½·¨ÊÇ¿ÉÄܻỨһµãʱ¼ä£¬µ«ÊÇ¿ÉÒÔÈ¡ÏûµÄ·½·¨¡£
Å×InterruptedExceptionµÄ´ú±í·½·¨ÓУº
1. java.lang.Object ÀàµÄ wait ·½·¨
2. java.lang.Thread ÀàµÄ sleep ·½·¨
3. java.lang.Thread ÀàµÄ join ·½·¨
-- ÐèÒª»¨µãʱ¼äµÄ·½·¨
Ö´ÐÐwait·½·¨µÄỊ̈߳¬»á½øÈëµÈ´ýÇøµÈ´ý±»notify/notify All¡£ÔڵȴýÆڼ䣬Ï̲߳»»á»î¶¯¡£
Ö´ÐÐsleep·½·¨µÄỊ̈߳¬»áÔÝÍ£Ö´ÐвÎÊýÄÚËùÉèÖõÄʱ¼ä¡£
Ö´ÐÐjoin·½·¨µÄỊ̈߳¬»áµÈ´ýµ½Ö¸¶¨µÄÏ߳̽áÊøΪֹ¡£
Òò´Ë£¬ÉÏÃæµÄ·½·¨¶¼ÊÇÐèÒª»¨µãʱ¼äµÄ·½·¨¡£
-- ¿ÉÒÔÈ¡ÏûµÄ·½·¨
ÒòΪÐèÒª»¨Ê±¼äµÄ²Ù×÷»á½µµÍ³ÌÐòµÄÏìÓ¦ÐÔ£¬ËùÒÔ¿ÉÄÜ»áÈ¡Ïû/ÖÐ;·ÅÆúÖ´ÐÐÕâ¸ö·½·¨¡£
ÕâÀïÖ÷ÒªÊÇͨ¹ýinterrupt·½·¨À´È¡Ïû¡£
1. sleep·½·¨Óëinterrupt·½·¨
interrupt·½·¨ÊÇThreadÀàµÄʵÀý·½·¨£¬ÔÚÖ´ÐеÄʱºò²¢²»ÐèÒª»ñÈ¡ThreadʵÀýµÄËø¶¨£¬ÈκÎÏß³ÌÔÚÈκÎʱ¿Ì£¬¶¼¿ÉÒÔͨ¹ýÏß³ÌʵÀýÀ´µ÷ÓÃÆäËûÏ̵߳Äinterrupt·½·¨¡£
µ±ÔÚsleepÖеÄÏ̱߳»µ÷ÓÃinterrupt·½·¨Ê±£¬¾Í»á·ÅÆúÔÝÍ£µÄ״̬£¬²¢Å׳öInterruptedExceptionÒì³££¬ÕâÑùÒ»À´£¬Ï̵߳ĿØÖÆȨ¾Í½»¸øÁ˲¶×½Õâ¸öÒì³£µÄcatch¿éÁË¡£
2. wait·½·¨ºÍinterrupt·½·¨
µ±Ï̵߳÷ÓÃwait·½·¨ºó£¬Ïß³ÌÔÚ½øÈëµÈ´ýÇøʱ£¬»á°ÑËø¶¨½Ó´¥¡£µ±¶ÔwaitÖеÄÏ̵߳÷ÓÃinterrupt·½·¨Ê±£¬»áÏÈÖØлñÈ¡Ëø¶¨£¬ÔÙÅ׳öInterruptedExceptionÒì³££¬»ñÈ¡Ëø¶¨Ö®Ç°£¬ÎÞ·¨Å׳öInterruptedExceptionÒì³£¡£
3. join·½·¨ºÍinterrupt·½·¨
µ±Ïß³ÌÒÔjoin·½·¨µÈ´ýÆäËûÏ߳̽áÊøʱ£¬Ò»Ñù¿ÉÒÔʹÓÃinterrupt·½·¨È¡Ïû¡£ÒòΪjoin·½·¨²»ÐèÒª»ñÈ¡Ëø¶¨£¬¹Ê¶øÓësleepÒ»Ñù£¬»áÂíÉÏÌøµ½catch³ÌÐò¿é
-- interrupt·½·¨¸ÉÁËʲô£¿
interrupt·½·¨ÆäʵֻÊǸıäÁËÖжÏ״̬¶øÒÑ¡£
¶øsleep¡¢waitºÍjoinÕâЩ·½·¨µÄÄÚ²¿»á²»¶ÏµÄ¼ì²éÖжÏ״̬µÄÖµ£¬´Ó¶ø×Ô¼ºÅ׳öInterruptEdException¡£
ËùÒÔ£¬Èç¹ûÔÚÏ߳̽øÐÐÆäËû´¦Àíʱ£¬µ÷ÓÃÁËËüµÄinterrupt·½·¨£¬Ïß³ÌÒ²²»»áÅ׳öInterruptedExceptionµÄ£¬Ö»Óе±Ïß³Ì×ßµ½ÁËsleep, wait, joinÕâЩ·½·¨µÄʱºò£¬²Å»áÅ׳öInterruptedException¡£ÈôÊÇûÓе÷ÓÃsleep, wait, joinÕâЩ·½·¨£¬»òÕßûÓÐÔÚÏß³ÌÀï×Ô¼º¼ì²éÖжÏ״̬£¬×Ô¼ºÅ׳öInterruptedException£¬ÄÇInterruptedExceptionÊDz»»áÅ׳öÀ´µÄ¡£
isInterrupted·½·¨£¬¿ÉÒÔÓÃÀ´¼ì²éÖжÏ״̬
Thread.interrupted·½·¨£¬¿ÉÒÔÓÃÀ´¼ì²é²¢Çå³ýÖжÏ״̬¡£
----------------------------------------------------
±¾ÎÄÖ÷Òª
Ïà¹ØÎĵµ£º
Java NIO APIÏê½â
ÔÚJDK
1.4ÒÔÇ°£¬JavaµÄIO²Ù×÷¼¯ÖÐÔÚjava.ioÕâ¸ö°üÖУ¬ÊÇ»ùÓÚÁ÷µÄ×èÈû£¨blocking£©API¡£¶ÔÓÚ´ó¶àÊýÓ¦ÓÃÀ´Ëµ£¬ÕâÑùµÄAPIʹÓúܷ½
±ã£¬È»¶ø£¬Ò»Ð©¶ÔÐÔÄÜÒªÇó½Ï¸ßµÄÓ¦Óã¬ÓÈÆäÊÇ·þÎñ¶ËÓ¦Óã¬ÍùÍùÐèÒªÒ»¸ö¸üΪÓÐЧµÄ·½Ê½À´´¦ÀíIO¡£´ÓJDK 1.4Æð£¬NIO
API×÷Ϊһ¸ö»ùÓÚ»º³åÇø£¬²¢ÄÜÌṩ·Ç×èÈû(non-blo ......
1¡¢½ø³ÌÓëỊ̈߳º
¡¶1¡·Ê²Ã´Êǽø³Ì£ºÊÇÖ¸ÔËÐÐÖеÄÓ¦ÓóÌÐò£¬Ã¿Ò»¸ö½ø³Ì¶¼ÓÐ×Ô¼º¶ÀÁ¢µÄÄÚ´æ¿Õ¼ä£¬
Ò»¸öÓ¦ÓóÌÐò¿ÉÒÔͬʱÆô¶¯¶à¸ö½ø³Ì£¬(¾²Ì¬)±ÈÈ磨IE£¬JVM£©
¡¶2¡·Ê²Ã´ÊÇỊ̈߳ºÊÇÖ¸½ø³ÌÖеÄÒ»¸öÖ´ÐÐÁ÷³Ì£¬ ......
WindowsMobileϵͳÎÞ·¨Ö±½Ó¹ÜÀíJAVA²å¼þ£¬ÐèÒª½èÖúJAVAÐéÄâ»úÀ´¹ÜÀíJAVA²å¼þ£¬WMƽ̨³£¼ûµÄJAVAÐéÄâ»úÓÐJbedºÍJblend¡£ÏÂÃæ¾ÍWMƽ̨¹ÜÀíJAVA²å¼þ×ö¼òÒª½éÉÜ¡£
1¡¢Jbed
Esmertec¹«Ë¾µÄ²úÆ·£¬ÍⲿÃüÁî¹ÜÀí·½Ê½Îª£º
°²×°£º\Windows\jbed.exe -DFile.maxStorageSize=64M -ginstall \" ......
ÔÚ¿´µ½Thinking in java µÚËÄÕÂʱ³õʼ»¯Ïà¹ØÎÊÌâµÄʱºò£¬ÎÒÃDz»ÓɵذÑ×¢ÒâÁ¦ÒƵ½¹¹ÔìÆ÷ÉÏ¡£ÕâÀï×ö¸ö¼òµ¥µÄ×ܽᣬ±ãÓÚ¸ßÊÖÖ¸ÕýÒÔ¼°×Ô¼ºÎ¹ʡ£
Ê×Ïȹ¹ÔìÆ÷ÊÇÒª¹¹ÔìÒ»¸ö¶«Î÷{¹¹Ôì¶ÔÏó£¨ÊµÀý£©}²¢¶ÔÆä³õʼ»¯¡£Ö®ËùÒÔ ......
Producer-Consumer PatternµÄ²ÎÓëÕߣº
1. Data²ÎÓëÕß
±»Producer²ÎÓëÕßËù´´½¨£¬²¢ÓÉConsumer²ÎÓëÕßËùʹÓá£
2. Producer£¨Éú²úÕߣ©²ÎÓëÕß
´´½¨Data²ÎÓëÕߣ¬²¢½«Æä´«µÝ¸øChannel²ÎÓëÕß¡£
3. Consumer£¨Ïû·ÑÕߣ©²ÎÓëÕß
´ÓChannel²ÎÓëÕß»ñÈ¡Data²ÎÓëÕß¡ ......