Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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ÖÐJList¼òµ¥Ó¦ÓÃ

 ×î½üѧϰjavaÓõ½ÁËJList,¶ÔÓÚÏòJListÖÐÌí¼ÓÊý¾Ý£¬À§ÈÅÁ˺þã¬ÉÏÍø²é¸øµÄ´ð°¸¶¼Ã»¸öºÏÊʵģ¬ÎÊÁËÀÏʦ²ÅŪÃ÷°×Щ£¬×ܽáÈçÏ£º
1.ʹÓÃVector£ºÊ×ÏÈ°ÑÄãµÄÊý¾ÝÏ´æ·ÅÔÚVectorÖУ¬È»ºóµ÷ÓÃJListµÄsetListData()·½·¨£¬½«VectorÌí¼Óµ½JListÖÐ
   Vector vt=new Vector();
   JList list=new JLis ......

javaÖгõʼ»¯Ë³Ðò£¨×ª£©

£¨1£©³õʼ»¯µÄ˳Ðò£¨¾²Ì¬¡¢·Ç¾²Ì¬¡¢final¡¢±äÁ¿¡¢¶ÔÏó£©
    ¶ÔÓÚ¾²Ì¬±äÁ¿¡¢¾²Ì¬³õʼ»¯¿é¡¢±äÁ¿¡¢³õʼ»¯¿é¡¢¹¹ÔìÆ÷£¬ËüÃǵijõʼ»¯Ë³ÐòÒÀ´ÎÊÇ£¨¾²Ì¬±äÁ¿¡¢¾²Ì¬³õʼ»¯¿é£©>£¨±äÁ¿¡¢³õʼ»¯¿é£©>¹¹ÔìÆ÷¡£
ÎÒÃÇÒ²¿ÉÒÔͨ¹ýÏÂÃæµÄ²âÊÔ´úÂëÀ´ÑéÖ¤ÕâÒ»µã£º
Java´úÂ룺
public class InitialOrderTest {
......

JavaÖÐnewºÍnewInstanceµÄÇø±ð

    ÔÚJavaÖУ¬Ê¹ÓÃnew¹Ø¼ü×ÖºÍClass.forName("a.class.Name").newInstance¶¼¿ÉÒÔ´´½¨¶ÔÏó£¬ËüÃÇÓÖÓÐʲôÇø±ðÄØ£¿
    1¡¢ÀàµÄ¼ÓÔØ·½Ê½²»Í¬¡£
    ÔÚÖ´ÐÐClass.forName("a.class.Name")ʱ£¬JVM»áÔÚclassapthÖÐÈ¥ÕÒ¶ÔÓ¦µÄÀಢ¼ÓÔØ£¬ÕâʱJVM»áÖ´ÐиÃÀàµÄ¾²Ì¬´úÂë¶Î¡£ÔÚʹÓà ......

JavaÏß³ÌÖ®Producer

 Producer-Consumer PatternµÄ²ÎÓëÕߣº
1. Data²ÎÓëÕß
    ±»Producer²ÎÓëÕßËù´´½¨£¬²¢ÓÉConsumer²ÎÓëÕßËùʹÓá£
2. Producer£¨Éú²úÕߣ©²ÎÓëÕß
    ´´½¨Data²ÎÓëÕߣ¬²¢½«Æä´«µÝ¸øChannel²ÎÓëÕß¡£
3. Consumer£¨Ïû·ÑÕߣ©²ÎÓëÕß
    ´ÓChannel²ÎÓëÕß»ñÈ¡Data²ÎÓëÕß¡ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ