ÃæÊÔÊÇÒ»ÖÖ¾¹ý×éÖ¯Õß¾«ÐÄÉè¼Æ£¬ÔÚÌض¨³¡¾°Ï£¬ÒÔ¿¼¹Ù¶Ô¿¼ÉúµÄÃæ¶ÔÃ潻̸Óë¹Û²ìΪÖ÷ÒªÊֶΣ¬ÓÉ±í¼°Àï²âÆÀ¿¼ÉúµÄ֪ʶ¡¢ÄÜÁ¦¡¢¾ÑéµÈÓйØËØÖʵÄÒ»ÖÖ¿¼ÊԻ¡£ÏÂÃæÊÇС±àÊÕ¼¯ÕûÀíµÄJavaÃæÊÔ±ÊÊÔÌ⣬ϣÍû¶ÔÄúÓÐËù°ïÖú!
JavaÃæÊÔ±ÊÊÔÌâ1) ʲôÊÇÏß³Ì?
Ïß³ÌÊDzÙ×÷ϵͳÄܹ»½øÐÐÔËËãµ÷¶ÈµÄ×îСµ¥Î»£¬Ëü±»°üº¬ÔÚ½ø³ÌÖ®ÖУ¬Êǽø³ÌÖеÄʵ¼ÊÔË×÷µ¥Î»¡£³ÌÐòÔ±¿ÉÒÔͨ¹ýËü½øÐжദÀíÆ÷±à³Ì£¬Äã¿ÉÒÔʹÓöàÏ̶߳ÔÔËËãÃܼ¯ÐÍÈÎÎñÌáËÙ¡£±ÈÈ磬Èç¹ûÒ»¸öÏß³ÌÍê³ÉÒ»¸öÈÎÎñÒª100ºÁÃ룬ÄÇôÓÃÊ®¸öÏß³ÌÍê³É¸ÄÈÎÎñÖ»Ðè10ºÁÃë¡£JavaÔÚÓïÑÔ²ãÃæ¶Ô¶àÏß³ÌÌṩÁË׿ԽµÄÖ§³Ö£¬ËüÒ²ÊÇÒ»¸öºÜºÃµÄÂôµã¡£ÓûÁ˽â¸ü¶àÏêϸÐÅÏ¢Çëµã»÷ÕâÀï¡£
2) Ï̺߳ͽø³ÌÓÐʲôÇø±ð?
Ïß³ÌÊǽø³ÌµÄ×Ó¼¯£¬Ò»¸ö½ø³Ì¿ÉÒÔÓкܶàỊ̈߳¬Ã¿ÌõÏ̲߳¢ÐÐÖ´Ðв»Í¬µÄÈÎÎñ¡£²»Í¬µÄ½ø³ÌʹÓò»Í¬µÄÄÚ´æ¿Õ¼ä£¬¶øËùÓеÄÏ̹߳²ÏíһƬÏàͬµÄÄÚ´æ¿Õ¼ä¡£±ð°ÑËüºÍÕ»ÄÚ´æ¸ã»ì£¬Ã¿¸öÏ̶߳¼ÓµÓе¥¶ÀµÄÕ»ÄÚ´æÓÃÀ´´æ´¢±¾µØÊý¾Ý¡£¸ü¶àÏêϸÐÅÏ¢Çëµã»÷ÕâÀï¡£
3) ÈçºÎÔÚJavaÖÐʵÏÖÏß³Ì?
ÔÚÓïÑÔ²ãÃæÓÐÁ½ÖÖ·½Ê½¡£java.lang.Thread ÀàµÄʵÀý¾ÍÊÇÒ»¸öÏ̵߳«ÊÇËüÐèÒªµ÷ÓÃjava.lang.Runnable½Ó¿ÚÀ´Ö´ÐУ¬ÓÉÓÚÏß³ÌÀà±¾Éí¾ÍÊǵ÷ÓõÄRunnable½Ó¿ÚËùÒÔÄã¿ÉÒԼ̳Ðjava.lang.Thread Àà»òÕßÖ±½Óµ÷ÓÃRunnable½Ó¿ÚÀ´ÖØдrun()·½·¨ÊµÏÖÏ̡߳£¸ü¶àÏêϸÐÅÏ¢Çëµã»÷ÕâÀï.
4) ÓÃRunnable»¹ÊÇThread?
Õâ¸öÎÊÌâÊÇÉÏÌâµÄºóÐø£¬´ó¼Ò¶¼ÖªµÀÎÒÃÇ¿ÉÒÔͨ¹ý¼Ì³ÐThreadÀà»òÕßµ÷ÓÃRunnable½Ó¿ÚÀ´ÊµÏÖỊ̈߳¬ÎÊÌâÊÇ£¬ÄǸö·½·¨¸üºÃÄØ?ʲôÇé¿öÏÂʹÓÃËü?Õâ¸öÎÊÌâºÜÈÝÒ׻شð£¬Èç¹ûÄãÖªµÀJava²»Ö§³ÖÀàµÄ¶àÖؼ̳У¬µ«ÔÊÐíÄãµ÷Óöà¸ö½Ó¿Ú¡£ËùÒÔÈç¹ûÄãÒª¼Ì³ÐÆäËûÀ࣬µ±È»Êǵ÷ÓÃRunnable½Ó¿ÚºÃÁË¡£¸ü¶àÏêϸÐÅÏ¢Çëµã»÷ÕâÀï¡£
6) Thread ÀàÖеÄstart() ºÍ run() ·½·¨ÓÐʲôÇø±ð?
Õâ¸öÎÊÌâ¾³£±»Îʵ½£¬µ«»¹ÊÇÄÜ´Ó´ËÇø·Ö³öÃæÊÔÕ߶ÔJavaÏß³ÌÄ£Ð͵ÄÀí½â³Ì¶È¡£start()·½·¨±»ÓÃÀ´Æô¶¯Ð´´½¨µÄỊ̈߳¬¶øÇÒstart()ÄÚ²¿µ÷ÓÃÁËrun()·½·¨£¬ÕâºÍÖ±½Óµ÷ÓÃrun()·½·¨µÄЧ¹û²»Ò»Ñù¡£µ±Äãµ÷ÓÃrun()·½·¨µÄʱºò£¬Ö»»áÊÇÔÚÔÀ´µÄÏß³ÌÖе÷Óã¬Ã»ÓÐеÄÏß³ÌÆô¶¯£¬start()·½·¨²Å»áÆô¶¯ÐÂÏ̡߳£¸ü¶àÌÖÂÛÇëµã»÷ÕâÀï
7) JavaÖÐRunnableºÍCallableÓÐʲô²»Í¬?
RunnableºÍCallable¶¼´ú±íÄÇЩҪÔÚ²»Í¬µÄÏß³ÌÖÐÖ´ÐеÄÈÎÎñ¡£Runnable´ÓJDK1.0¿ªÊ¼¾ÍÓÐÁË£¬CallableÊÇÔÚJDK1.5Ôö¼ÓµÄ¡£ËüÃǵÄÖ÷ÒªÇø±ðÊÇCallableµÄ call() ·½·¨¿ÉÒÔ·µ»ØÖµºÍÅ׳öÒì³££¬¶øRunnableµÄrun()·½·¨Ã»ÓÐÕâЩ¹¦ÄÜ¡£Callable¿ÉÒÔ·µ»Ø×°ÔØÓмÆËã½á¹ûµÄFuture¶ÔÏó¡£ÎҵIJ©¿ÍÓиüÏêϸµÄ˵Ã÷¡£
8) JavaÖÐCyclicBarrier ºÍ CountDownLatchÓÐʲô²»Í¬?
CyclicBarrier ºÍ CountDownLatch ¶¼¿ÉÒÔÓÃÀ´ÈÃÒ»×éÏ̵߳ȴýÆäËüÏ̡߳£Óë CyclicBarrier ²»Í¬µÄÊÇ£¬CountdownLatch ²»ÄÜÖØÐÂʹÓᣵã´Ë²é¿´¸ü¶àÐÅÏ¢ºÍʾÀý´úÂë¡£
9) JavaÄÚ´æÄ£ÐÍÊÇʲô?
JavaÄÚ´æÄ£Ð͹涨ºÍÖ¸ÒýJava³ÌÐòÔÚ²»Í¬µÄÄÚ´æ¼Ü¹¹¡¢CPUºÍ²Ù×÷ϵͳ¼äÓÐÈ·¶¨ÐÔµØÐÐΪ¡£ËüÔÚ¶àÏ̵߳ÄÇé¿öÏÂÓÈÆäÖØÒª¡£JavaÄÚ´æÄ£ÐͶÔÒ»¸öÏß³ÌËù×öµÄ±ä¶¯Äܱ»ÆäËüÏ߳̿ɼûÌṩÁ˱£Ö¤£¬ËüÃÇÖ®¼äÊÇÏÈÐз¢Éú¹Øx¡£Õâ¸ö¹Øϵ¶¨ÒåÁËһЩ¹æÔòÈóÌÐòÔ±ÔÚ²¢·¢±à³Ìʱ˼·¸üÇåÎú¡£±ÈÈ磬ÏÈÐз¢Éú¹ØxÈ·±£ÁË£º
Ïß³ÌÄڵĴúÂëÄܹ»°´ÏȺó˳ÐòÖ´ÐУ¬Õâ±»³ÆΪ³ÌÐò´ÎÐò¹æÔò¡£
¶ÔÓÚͬһ¸öËø£¬Ò»¸ö½âËø²Ù×÷Ò»¶¨Òª·¢ÉúÔÚʱ¼äÉϺó·¢ÉúµÄÁíÒ»¸öËø¶¨²Ù×÷֮ǰ£¬Ò²½Ð×ö¹Ü³ÌËø¶¨¹æÔò¡£
Ç°Ò»¸ö¶ÔvolatileµÄд²Ù×÷ÔÚºóÒ»¸övolatileµÄ¶Á²Ù×÷֮ǰ£¬Ò²½Ðvolatile±äÁ¿¹æÔò¡£
Ò»¸öÏß³ÌÄÚµÄÈκβÙ×÷±ØÐèÔÚÕâ¸öÏ̵߳Ästart()µ÷ÓÃÖ®ºó£¬Ò²½Ð×÷Ïß³ÌÆô¶¯¹æÔò¡£
Ò»¸öÏ̵߳ÄËùÓвÙ×÷¶¼»áÔÚÏß³ÌÖÕֹ֮ǰ£¬Ïß³ÌÖÕÖ¹¹æÔò¡£
Ò»¸ö¶ÔÏóµÄÖÕ½á²Ù×÷±ØÐèÔÚÕâ¸ö¶ÔÏó¹¹ÔìÍê³ÉÖ®ºó£¬Ò²½Ð¶ÔÏóÖÕ½á¹æÔò¡£
¿É´«µÝÐÔ
ÎÒÇ¿ÁÒ½¨Òé´ó¼ÒÔĶÁ¡¶Java²¢·¢±à³Ìʵ¼ù¡·µÚÊ®ÁùÕÂÀ´¼ÓÉî¶ÔJavaÄÚ´æÄ£Ð͵ÄÀí½â¡£
10) JavaÖеÄvolatile ±äÁ¿ÊÇʲô?
volatileÊÇÒ»¸öÌØÊâµÄÐÞÊηû£¬Ö»ÓгÉÔ±±äÁ¿²ÅÄÜʹÓÃËü¡£ÔÚJava²¢·¢³ÌÐòȱÉÙͬ²½ÀàµÄÇé¿öÏ£¬¶àÏ̶߳ԳÉÔ±±äÁ¿µÄ²Ù×÷¶ÔÆäËüÏß³ÌÊÇ͸Ã÷µÄ¡£volatile±äÁ¿¿ÉÒÔ±£Ö¤ÏÂÒ»¸ö¶ÁÈ¡²Ù×÷»áÔÚÇ°Ò»¸öд²Ù×÷Ö®ºó·¢Éú£¬¾ÍÊÇÉÏÒ»ÌâµÄvolatile±äÁ¿¹æÔò¡£µã»÷ÕâÀï²é¿´¸ü¶àvolatileµÄÏà¹ØÄÚÈÝ¡£
11) ʲôÊÇḬ̈߳²È«?VectorÊÇÒ»¸öḬ̈߳²È«ÀàÂð? (Ïê¼ûÕâÀï)
Èç¹ûÄãµÄ´úÂëËùÔڵĽø³ÌÖÐÓжà¸öÏß³ÌÔÚͬʱÔËÐУ¬¶øÕâЩÏ߳̿ÉÄÜ»áͬʱÔËÐÐÕâ¶Î´úÂë¡£Èç¹ûÿ´ÎÔËÐнá¹ûºÍµ¥Ïß³ÌÔËÐеĽá¹ûÊÇÒ»ÑùµÄ£¬¶øÇÒÆäËûµÄ±äÁ¿µÄÖµÒ²ºÍÔ¤ÆÚµÄÊÇÒ»ÑùµÄ£¬¾ÍÊÇḬ̈߳²È«µÄ¡£Ò»¸öḬ̈߳²È«µÄ¼ÆÊýÆ÷ÀàµÄͬһ¸öʵÀý¶ÔÏóÔÚ±»¶à¸öÏß³ÌʹÓõÄÇé¿öÏÂÒ²²»»á³öÏÖ¼ÆËãʧÎ󡣺ÜÏÔÈ»Äã¿ÉÒÔ½«¼¯ºÏÀà·Ö³ÉÁ½×飬Ḭ̈߳²È«ºÍ·ÇḬ̈߳²È«µÄ¡£Vector ÊÇÓÃͬ²½·½·¨À´ÊµÏÖḬ̈߳²È«µÄ, ¶øºÍËüÏàËƵÄArrayList²»ÊÇḬ̈߳²È«µÄ¡£
12) JavaÖÐʲôÊǾºÌ¬Ìõ¼þ? ¾Ù¸öÀý×Ó˵Ã÷¡£
¾ºÌ¬Ìõ¼þ»áµ¼Ö³ÌÐòÔÚ²¢·¢Çé¿öϳöÏÖһЩbugs¡£¶àÏ̶߳ÔһЩ×ÊÔ´µÄ¾ºÕùµÄʱºò¾Í»á²úÉú¾ºÌ¬Ìõ¼þ£¬Èç¹ûÊ×ÏÈÒªÖ´ÐеijÌÐò¾ºÕùʧ°ÜÅŵ½ºóÃæÖ´ÐÐÁË£¬ÄÇôÕû¸ö³ÌÐò¾Í»á³öÏÖһЩ²»È·¶¨µÄbugs¡£ÕâÖÖbugsºÜÄÑ·¢ÏÖ¶øÇÒ»áÖظ´³öÏÖ£¬ÒòΪÏ̼߳äµÄËæ»ú¾ºÕù¡£Ò»¸öÀý×Ó¾ÍÊÇÎÞÐò´¦Àí£¬Ïê¼û´ð°¸¡£
13) JavaÖÐÈçºÎÍ£Ö¹Ò»¸öÏß³Ì?
JavaÌṩÁ˺ܷḻµÄAPIµ«Ã»ÓÐΪֹͣÏß³ÌÌṩAPI¡£JDK 1.0±¾À´ÓÐһЩÏñstop(), suspend() ºÍ resume()µÄ¿ØÖÆ·½·¨µ«ÊÇÓÉÓÚDZÔÚµÄËÀËøÍþвÒò´ËÔÚºóÐøµÄJDK°æ±¾ÖÐËûÃDZ»ÆúÓÃÁË£¬Ö®ºóJava APIµÄÉè¼ÆÕß¾ÍûÓÐÌṩһ¸ö¼æÈÝÇÒḬ̈߳²È«µÄ·½·¨À´Í£Ö¹Ò»¸öÏ̡߳£µ±run() »òÕß call() ·½·¨Ö´ÐÐÍêµÄʱºòÏ̻߳á×Ô¶¯½áÊø,Èç¹ûÒªÊÖ¶¯½áÊøÒ»¸öỊ̈߳¬Äã¿ÉÒÔÓÃvolatile ²¼¶û±äÁ¿À´Í˳örun()·½·¨µÄÑ»·»òÕßÊÇÈ¡ÏûÈÎÎñÀ´ÖжÏÏ̡߳£µã»÷ÕâÀï²é¿´Ê¾Àý´úÂë¡£
14) Ò»¸öÏß³ÌÔËÐÐʱ·¢ÉúÒì³£»áÔõÑù?
ÕâÊÇÎÒÔÚÒ»´ÎÃæÊÔÖÐÓöµ½µÄÒ»¸öºÜµó×êµÄJavaÃæÊÔÌâ, ¼òµ¥µÄ˵£¬Èç¹ûÒ쳣ûÓб»²¶»ñ¸ÃÏ߳̽«»áÍ£Ö¹Ö´ÐС£Thread.UncaughtExceptionHandlerÊÇÓÃÓÚ´¦Àí䲶»ñÒì³£Ôì³ÉÏß³ÌͻȻÖжÏÇé¿öµÄÒ»¸öÄÚǶ½Ó¿Ú¡£µ±Ò»¸ö䲶»ñÒì³£½«Ôì³ÉÏß³ÌÖжϵÄʱºòJVM»áʹÓÃThread.getUncaughtExceptionHandler()À´²éѯÏ̵߳ÄUncaughtExceptionHandler²¢½«Ï̺߳ÍÒì³£×÷Ϊ²ÎÊý´«µÝ¸øhandlerµÄuncaughtException()·½·¨½øÐд¦Àí¡£
15) ÈçºÎÔÚÁ½¸öÏ̼߳乲ÏíÊý¾Ý?
Äã¿ÉÒÔͨ¹ý¹²Ïí¶ÔÏóÀ´ÊµÏÖÕâ¸öÄ¿µÄ£¬»òÕßÊÇʹÓÃÏñ×èÈû¶ÓÁÐÕâÑù²¢·¢µÄÊý¾Ý½á¹¹¡£Õâƪ½Ì³Ì¡¶JavaÏ̼߳äͨÐÅ¡·(Éæ¼°µ½ÔÚÁ½¸öÏ̼߳乲Ïí¶ÔÏó)ÓÃwaitºÍnotify·½·¨ÊµÏÖÁËÉú²úÕßÏû·ÑÕßÄ£ÐÍ¡£
16) JavaÖÐnotify ºÍ notifyAllÓÐʲôÇø±ð?
ÕâÓÖÊÇÒ»¸öµó×êµÄÎÊÌ⣬ÒòΪ¶àÏ߳̿ÉÒԵȴýµ¥¼à¿ØËø£¬Java API µÄÉè¼ÆÈËÔ±ÌṩÁËһЩ·½·¨µ±µÈ´ýÌõ¼þ¸Ä±äµÄʱºò֪ͨËüÃÇ£¬µ«ÊÇÕâЩ·½·¨Ã»ÓÐÍêȫʵÏÖ¡£notify()·½·¨²»ÄÜ»½ÐÑij¸ö¾ßÌåµÄỊ̈߳¬ËùÒÔÖ»ÓÐÒ»¸öÏß³ÌÔڵȴýµÄʱºòËü²ÅÓÐÓÃÎäÖ®µØ¡£¶ønotifyAll()»½ÐÑËùÓÐÏ̲߳¢ÔÊÐíËûÃÇÕù¶áËøÈ·±£ÁËÖÁÉÙÓÐÒ»¸öÏß³ÌÄܼÌÐøÔËÐС£ÎҵIJ©¿ÍÓиüÏêϸµÄ×ÊÁϺÍʾÀý´úÂë¡£
17) Ϊʲôwait, notify ºÍ notifyAllÕâЩ·½·¨²»ÔÚthreadÀàÀïÃæ?
ÕâÊǸöÉè¼ÆÏà¹ØµÄÎÊÌ⣬Ëü¿¼²ìµÄÊÇÃæÊÔÕ߶ÔÏÖÓÐϵͳºÍһЩÆÕ±é´æÔÚµ«¿´ÆðÀ´²»ºÏÀíµÄÊÂÎïµÄ¿´·¨¡£»Ø´ðÕâЩÎÊÌâµÄʱºò£¬ÄãҪ˵Ã÷Ϊʲô°ÑÕâЩ·½·¨·ÅÔÚObjectÀàÀïÊÇÓÐÒâÒåµÄ£¬»¹Óв»°ÑËü·ÅÔÚThreadÀàÀïµÄÔÒò¡£Ò»¸öºÜÃ÷ÏÔµÄÔÒòÊÇJAVAÌṩµÄËøÊǶÔÏ󼶵Ķø²»ÊÇÏ̼߳¶µÄ£¬Ã¿¸ö¶ÔÏó¶¼ÓÐËø£¬Í¨¹ýÏ̻߳ñµÃ¡£Èç¹ûÏß³ÌÐèÒªµÈ´ýijЩËøÄÇôµ÷ÓöÔÏóÖеÄwait()·½·¨¾ÍÓÐÒâÒåÁË¡£Èç¹ûwait()·½·¨¶¨ÒåÔÚThreadÀàÖУ¬Ïß³ÌÕýÔڵȴýµÄÊÇÄĸöËø¾Í²»Ã÷ÏÔÁË¡£¼òµ¥µÄ˵£¬ÓÉÓÚwait£¬notifyºÍnotifyAll¶¼ÊÇËø¼¶±ðµÄ²Ù×÷£¬ËùÒÔ°ÑËûÃǶ¨ÒåÔÚObjectÀàÖÐÒòΪËøÊôÓÚ¶ÔÏó¡£ÄãÒ²¿ÉÒԲ鿴ÕâƪÎÄÕÂÁ˽â¸ü¶à¡£
18) ʲôÊÇThreadLocal±äÁ¿?
ThreadLocalÊÇJavaÀïÒ»ÖÖÌØÊâµÄ±äÁ¿¡£Ã¿¸öÏ̶߳¼ÓÐÒ»¸öThreadLocal¾ÍÊÇÿ¸öÏ̶߳¼ÓµÓÐÁË×Ô¼º¶ÀÁ¢µÄÒ»¸ö±äÁ¿£¬¾ºÕùÌõ¼þ±»³¹µ×Ïû³ýÁË¡£ËüÊÇΪ´´½¨´ú¼Û¸ß°ºµÄ¶ÔÏó»ñÈ¡Ḭ̈߳²È«µÄºÃ·½·¨£¬±ÈÈçÄã¿ÉÒÔÓÃThreadLocalÈÃSimpleDateFormat±ä³ÉḬ̈߳²È«µÄ£¬ÒòΪÄǸöÀà´´½¨´ú¼Û¸ß°ºÇÒÿ´Îµ÷Óö¼ÐèÒª´´½¨²»Í¬µÄʵÀýËùÒÔ²»ÖµµÃÔÚ¾Ö²¿·¶Î§Ê¹ÓÃËü£¬Èç¹ûΪÿ¸öÏß³ÌÌṩһ¸ö×Ô¼º¶ÀÓеıäÁ¿¿½±´£¬½«´ó´óÌá¸ßЧÂÊ¡£Ê×ÏÈ£¬Í¨¹ý¸´ÓüõÉÙÁË´ú¼Û¸ß°ºµÄ¶ÔÏóµÄ´´½¨¸öÊý¡£Æä´Î£¬ÄãÔÚûÓÐʹÓøߴú¼ÛµÄͬ²½»òÕß²»±äÐÔµÄÇé¿öÏ»ñµÃÁËḬ̈߳²È«¡£Ïֲ߳̾¿±äÁ¿µÄÁíÒ»¸ö²»´íµÄÀý×ÓÊÇThreadLocalRandomÀ࣬ËüÔÚ¶àÏ̻߳·¾³ÖмõÉÙÁË´´½¨´ú¼Û¸ß°ºµÄRandom¶ÔÏóµÄ¸öÊý¡£²é¿´´ð°¸Á˽â¸ü¶à¡£
19) ʲôÊÇFutureTask?
ÔÚJava²¢·¢³ÌÐòÖÐFutureTask±íʾһ¸ö¿ÉÒÔÈ¡ÏûµÄÒì²½ÔËËã¡£ËüÓÐÆô¶¯ºÍÈ¡ÏûÔËËã¡¢²éѯÔËËãÊÇ·ñÍê³ÉºÍÈ¡»ØÔËËã½á¹ûµÈ·½·¨¡£Ö»Óе±ÔËËãÍê³ÉµÄʱºò½á¹û²ÅÄÜÈ¡»Ø£¬Èç¹ûÔËËãÉÐδÍê³Éget·½·¨½«»á×èÈû¡£Ò»¸öFutureTask¶ÔÏó¿ÉÒÔ¶Ôµ÷ÓÃÁËCallableºÍRunnableµÄ¶ÔÏó½øÐаü×°£¬ÓÉÓÚFutureTaskÒ²Êǵ÷ÓÃÁËRunnable½Ó¿ÚËùÒÔËü¿ÉÒÔÌá½»¸øExecutorÀ´Ö´ÐС£
20) JavaÖÐinterrupted ºÍ isInterruptedd·½·¨µÄÇø±ð?
interrupted() ºÍ isInterrupted()µÄÖ÷ÒªÇø±ðÊÇÇ°Õ߻ὫÖжÏ״̬Çå³ý¶øºóÕß²»»á¡£Java¶àÏ̵߳ÄÖжϻúÖÆÊÇÓÃÄÚ²¿±êʶÀ´ÊµÏֵģ¬µ÷ÓÃThread.interrupt()À´ÖжÏÒ»¸öÏ߳̾ͻáÉèÖÃÖжϱêʶΪtrue¡£µ±ÖжÏÏ̵߳÷Óþ²Ì¬·½·¨Thread.interrupted()À´¼ì²éÖжÏ״̬ʱ£¬ÖжÏ״̬»á±»ÇåÁã¡£¶ø·Ç¾²Ì¬·½·¨isInterrupted()ÓÃÀ´²éѯÆäËüÏ̵߳ÄÖжÏ״̬ÇÒ²»»á¸Ä±äÖжÏ״̬±êʶ¡£¼òµ¥µÄ˵¾ÍÊÇÈκÎÅ׳öInterruptedExceptionÒì³£µÄ·½·¨¶¼»á½«ÖжÏ״̬ÇåÁã¡£ÎÞÂÛÈçºÎ£¬Ò»¸öÏ̵߳ÄÖжÏ״̬ÓÐÓпÉÄܱ»ÆäËüÏ̵߳÷ÓÃÖжÏÀ´¸Ä±ä¡£
21) ΪʲôwaitºÍnotify·½·¨ÒªÔÚͬ²½¿éÖе÷ÓÃ?
Ö÷ÒªÊÇÒòΪJava APIÇ¿ÖÆÒªÇóÕâÑù×ö£¬Èç¹ûÄã²»Õâô×ö£¬ÄãµÄ´úÂë»áÅ׳öIllegalMonitorStateExceptionÒì³£¡£»¹ÓÐÒ»¸öÔÒòÊÇΪÁ˱ÜÃâwaitºÍnotifyÖ®¼ä²úÉú¾ºÌ¬Ìõ¼þ¡£
22) ΪʲôÄãÓ¦¸ÃÔÚÑ»·Öмì²éµÈ´ýÌõ¼þ?
´¦Óڵȴý״̬µÄÏ߳̿ÉÄÜ»áÊÕµ½´íÎ󾯱¨ºÍα»½ÐÑ£¬Èç¹û²»ÔÚÑ»·Öмì²éµÈ´ýÌõ¼þ£¬³ÌÐò¾Í»áÔÚûÓÐÂú×ã½áÊøÌõ¼þµÄÇé¿öÏÂÍ˳ö¡£Òò´Ë£¬µ±Ò»¸öµÈ´ýÏß³ÌÐÑÀ´Ê±£¬²»ÄÜÈÏΪËüÔÀ´µÄµÈ´ý״̬ÈÔÈ»ÊÇÓÐЧµÄ£¬ÔÚnotify()·½·¨µ÷ÓÃÖ®ºóºÍµÈ´ýÏß³ÌÐÑÀ´Ö®Ç°Õâ¶Îʱ¼äËü¿ÉÄÜ»á¸Ä±ä¡£Õâ¾ÍÊÇÔÚÑ»·ÖÐʹÓÃwait()·½·¨Ð§¹û¸üºÃµÄÔÒò£¬Äã¿ÉÒÔÔÚEclipseÖд´½¨Ä£°åµ÷ÓÃwaitºÍnotifyÊÔÒ»ÊÔ¡£Èç¹ûÄãÏëÁ˽â¸ü¶à¹ØÓÚÕâ¸öÎÊÌâµÄÄÚÈÝ£¬ÎÒÍƼöÄãÔĶÁ¡¶Effective Java¡·Õâ±¾ÊéÖеÄÏ̺߳Íͬ²½Õ½ڡ£
23) JavaÖеÄͬ²½¼¯ºÏÓë²¢·¢¼¯ºÏÓÐʲôÇø±ð?
ͬ²½¼¯ºÏÓë²¢·¢¼¯ºÏ¶¼Îª¶àÏ̺߳Ͳ¢·¢ÌṩÁ˺ÏÊʵÄḬ̈߳²È«µÄ¼¯ºÏ£¬²»¹ý²¢·¢¼¯ºÏµÄ¿ÉÀ©Õ¹ÐÔ¸ü¸ß¡£ÔÚJava1.5֮ǰ³ÌÐòÔ±ÃÇÖ»ÓÐͬ²½¼¯ºÏÀ´ÓÃÇÒÔÚ¶àÏ̲߳¢·¢µÄʱºò»áµ¼ÖÂÕùÓã¬×è°ÁËϵͳµÄÀ©Õ¹ÐÔ¡£Java5½éÉÜÁ˲¢·¢¼¯ºÏÏñConcurrentHashMap£¬²»½öÌṩḬ̈߳²È«»¹ÓÃËø·ÖÀëºÍÄÚ²¿·ÖÇøµÈÏÖ´ú¼¼ÊõÌá¸ßÁË¿ÉÀ©Õ¹ÐÔ¡£¸ü¶àÄÚÈÝÏê¼û´ð°¸¡£
24) JavaÖжѺÍÕ»ÓÐʲô²»Í¬?
Ϊʲô°ÑÕâ¸öÎÊÌâ¹éÀàÔÚ¶àÏ̺߳Ͳ¢·¢ÃæÊÔÌâÀï?ÒòΪջÊÇÒ»¿éºÍÏ߳̽ôÃÜÏà¹ØµÄÄÚ´æÇøÓò¡£Ã¿¸öÏ̶߳¼ÓÐ×Ô¼ºµÄÕ»Äڴ棬ÓÃÓÚ´æ´¢±¾µØ±äÁ¿£¬·½·¨²ÎÊýºÍÕ»µ÷Óã¬Ò»¸öÏß³ÌÖд洢µÄ±äÁ¿¶ÔÆäËüÏß³ÌÊDz»¿É¼ûµÄ¡£¶ø¶ÑÊÇËùÓÐÏ̹߳²ÏíµÄһƬ¹«ÓÃÄÚ´æÇøÓò¡£¶ÔÏó¶¼ÔÚ¶ÑÀï´´½¨£¬ÎªÁËÌáÉýЧÂÊÏ̻߳á´Ó¶ÑÖÐŪһ¸ö»º´æµ½×Ô¼ºµÄÕ»£¬Èç¹û¶à¸öÏß³ÌʹÓøñäÁ¿¾Í¿ÉÄÜÒý·¢ÎÊÌ⣬Õâʱvolatile ±äÁ¿¾Í¿ÉÒÔ·¢»Ó×÷ÓÃÁË£¬ËüÒªÇóÏ̴߳ÓÖ÷´æÖжÁÈ¡±äÁ¿µÄÖµ¡£
25) ʲôÊÇÏ̳߳Ø? ΪʲôҪʹÓÃËü?
´´½¨Ïß³ÌÒª»¨·Ñ°º¹óµÄ×ÊÔ´ºÍʱ¼ä£¬Èç¹ûÈÎÎñÀ´Á˲Ŵ´½¨Ïß³ÌÄÇôÏìӦʱ¼ä»á±ä³¤£¬¶øÇÒÒ»¸ö½ø³ÌÄÜ´´½¨µÄÏß³ÌÊýÓÐÏÞ¡£ÎªÁ˱ÜÃâÕâЩÎÊÌ⣬ÔÚ³ÌÐòÆô¶¯µÄʱºò¾Í´´½¨Èô¸ÉÏß³ÌÀ´ÏìÓ¦´¦Àí£¬ËüÃDZ»³ÆΪÏ̳߳أ¬ÀïÃæµÄÏ߳̽й¤×÷Ï̡߳£´ÓJDK1.5¿ªÊ¼£¬Java APIÌṩÁËExecutor¿ò¼ÜÈÃÄã¿ÉÒÔ´´½¨²»Í¬µÄÏ̳߳ء£±ÈÈçµ¥Ï̳߳أ¬Ã¿´Î´¦ÀíÒ»¸öÈÎÎñ;ÊýÄ¿¹Ì¶¨µÄÏ̳߳ػòÕßÊÇ»º´æÏ̳߳Ø(Ò»¸öÊʺϺܶàÉú´æÆڶ̵ÄÈÎÎñµÄ³ÌÐòµÄ¿ÉÀ©Õ¹Ï̳߳Ø)¡£¸ü¶àÄÚÈÝÏê¼ûÕâƪÎÄÕ¡£
26) ÈçºÎд´úÂëÀ´½â¾öÉú²úÕßÏû·ÑÕßÎÊÌâ?
ÔÚÏÖʵÖÐÄã½â¾öµÄÐí¶àÏß³ÌÎÊÌⶼÊôÓÚÉú²úÕßÏû·ÑÕßÄ£ÐÍ£¬¾ÍÊÇÒ»¸öÏß³ÌÉú²úÈÎÎñ¹©ÆäËüÏ߳̽øÐÐÏû·Ñ£¬Äã±ØÐëÖªµÀÔõô½øÐÐÏ̼߳äͨÐÅÀ´½â¾öÕâ¸öÎÊÌâ¡£±È½ÏµÍ¼¶µÄ°ì·¨ÊÇÓÃwaitºÍnotifyÀ´½â¾öÕâ¸öÎÊÌ⣬±È½ÏÔ޵İ취ÊÇÓÃSemaphore »òÕß BlockingQueueÀ´ÊµÏÖÉú²úÕßÏû·ÑÕßÄ£ÐÍ£¬Õâƪ½Ì³ÌÓÐʵÏÖËü¡£
27) ÈçºÎ±ÜÃâËÀËø?
Java¶àÏß³ÌÖеÄËÀËø
ËÀËøÊÇÖ¸Á½¸ö»òÁ½¸öÒÔÉϵĽø³ÌÔÚÖ´Ðйý³ÌÖУ¬ÒòÕù¶á×ÊÔ´¶øÔì³ÉµÄÒ»ÖÖ»¥ÏàµÈ´ýµÄÏÖÏó£¬ÈôÎÞÍâÁ¦×÷Óã¬ËüÃǶ¼½«ÎÞ·¨ÍƽøÏÂÈ¥¡£ÕâÊÇÒ»¸öÑÏÖصÄÎÊÌ⣬ÒòΪËÀËø»áÈÃÄãµÄ³ÌÐò¹ÒÆðÎÞ·¨Íê³ÉÈÎÎñ£¬ËÀËøµÄ·¢Éú±ØÐëÂú×ãÒÔÏÂËĸöÌõ¼þ£º
»¥³âÌõ¼þ£ºÒ»¸ö×ÊԴÿ´ÎÖ»Äܱ»Ò»¸ö½ø³ÌʹÓá£
ÇëÇóÓë±£³ÖÌõ¼þ£ºÒ»¸ö½ø³ÌÒòÇëÇó×ÊÔ´¶ø×èÈûʱ£¬¶ÔÒÑ»ñµÃµÄ×ÊÔ´±£³Ö²»·Å¡£
²»°þ¶áÌõ¼þ£º½ø³ÌÒÑ»ñµÃµÄ×ÊÔ´£¬ÔÚĩʹÓÃÍê֮ǰ£¬²»ÄÜÇ¿Ðаþ¶á¡£
Ñ»·µÈ´ýÌõ¼þ£ºÈô¸É½ø³ÌÖ®¼äÐγÉÒ»ÖÖͷβÏà½ÓµÄÑ»·µÈ´ý×ÊÔ´¹Øϵ¡£
±ÜÃâËÀËø×î¼òµ¥µÄ·½·¨¾ÍÊÇ×èֹѻ·µÈ´ýÌõ¼þ£¬½«ÏµÍ³ÖÐËùÓеÄ×ÊÔ´ÉèÖñê־λ¡¢ÅÅÐò£¬¹æ¶¨ËùÓеĽø³ÌÉêÇë×ÊÔ´±ØÐëÒÔÒ»¶¨µÄ˳Ðò(ÉýÐò»ò½µÐò)×ö²Ù×÷À´±ÜÃâËÀËø¡£Õâƪ½Ì³ÌÓдúÂëʾÀýºÍ±ÜÃâËÀËøµÄÌÖÂÛϸ½Ú¡£
28) JavaÖлîËøºÍËÀËøÓÐʲôÇø±ð?
ÕâÊÇÉÏÌâµÄÀ©Õ¹£¬»îËøºÍËÀËøÀàËÆ£¬²»Í¬Ö®´¦ÔÚÓÚ´¦ÓÚ»îËøµÄÏ̻߳ò½ø³ÌµÄ״̬ÊDz»¶Ï¸Ä±äµÄ£¬»îËø¿ÉÒÔÈÏΪÊÇÒ»ÖÖÌØÊâµÄ¼¢¶ö¡£Ò»¸öÏÖʵµÄ»îËøÀý×ÓÊÇÁ½¸öÈËÔÚÏÁСµÄ×ßÀÈÅöµ½£¬Á½¸öÈ˶¼ÊÔ×űÜÈöԷ½ºÃÈñ˴Ëͨ¹ý£¬µ«ÊÇÒòΪ±ÜÈõķ½Ïò¶¼Ò»Ñùµ¼ÖÂ×îºó˶¼²»ÄÜͨ¹ý×ßÀÈ¡£¼òµ¥µÄ˵¾ÍÊÇ£¬»îËøºÍËÀËøµÄÖ÷ÒªÇø±ðÊÇÇ°Õß½ø³ÌµÄ״̬¿ÉÒԸı䵫ÊÇÈ´²»ÄܼÌÐøÖ´ÐС£
29) Ôõô¼ì²âÒ»¸öÏß³ÌÊÇ·ñÓµÓÐËø?
ÎÒÒ»Ö±²»ÖªµÀÎÒÃǾ¹È»¿ÉÒÔ¼ì²âÒ»¸öÏß³ÌÊÇ·ñÓµÓÐËø£¬Ö±µ½ÎҲμÓÁËÒ»´Îµç»°ÃæÊÔ¡£ÔÚjava.lang.ThreadÖÐÓÐÒ»¸ö·½·¨½ÐholdsLock()£¬Ëü·µ»ØtrueÈç¹ûµ±ÇÒ½öµ±µ±Ç°Ïß³ÌÓµÓÐij¸ö¾ßÌå¶ÔÏóµÄËø¡£Äã¿ÉÒԲ鿴ÕâƪÎÄÕÂÁ˽â¸ü¶à¡£
30) ÄãÈçºÎÔÚJavaÖлñÈ¡Ï̶߳ÑÕ»?
¶ÔÓÚ²»Í¬µÄ²Ù×÷ϵͳ£¬ÓжàÖÖ·½·¨À´»ñµÃJava½ø³ÌµÄÏ̶߳ÑÕ»¡£µ±Äã»ñÈ¡Ï̶߳Ñջʱ£¬JVM»á°ÑËùÓÐÏ̵߳Ä״̬´æµ½ÈÕÖ¾Îļþ»òÕßÊä³öµ½¿ØÖÆ̨¡£ÔÚWindowsÄã¿ÉÒÔʹÓÃCtrl Break×éºÏ¼üÀ´»ñÈ¡Ï̶߳ÑÕ»£¬LinuxÏÂÓÃkill -3ÃüÁî¡£ÄãÒ²¿ÉÒÔÓÃjstackÕâ¸ö¹¤¾ßÀ´»ñÈ¡£¬Ëü¶ÔÏß³Ìid½øÐвÙ×÷£¬Äã¿ÉÒÔÓÃjpsÕâ¸ö¹¤¾ßÕÒµ½id¡£
31) JVMÖÐÄĸö²ÎÊýÊÇÓÃÀ´¿ØÖÆÏ̵߳ÄÕ»¶ÑջСµÄ
Õâ¸öÎÊÌâºÜ¼òµ¥£¬ -Xss²ÎÊýÓÃÀ´¿ØÖÆÏ̵߳ĶÑÕ»´óС¡£Äã¿ÉÒԲ鿴JVMÅäÖÃÁбíÀ´Á˽âÕâ¸ö²ÎÊýµÄ¸ü¶àÐÅÏ¢¡£
32) JavaÖÐsynchronized ºÍ ReentrantLock ÓÐʲô²»Í¬?
JavaÔÚ¹ýÈ¥ºÜ³¤Ò»¶Îʱ¼äÖ»ÄÜͨ¹ýsynchronized¹Ø¼ü×ÖÀ´ÊµÏÖ»¥³â£¬ËüÓÐһЩȱµã¡£±ÈÈçÄã²»ÄÜÀ©Õ¹ËøÖ®ÍâµÄ·½·¨»òÕß¿é±ß½ç£¬³¢ÊÔ»ñÈ¡Ëøʱ²»ÄÜÖÐ;ȡÏûµÈ¡£Java 5 ͨ¹ýLock½Ó¿ÚÌṩÁ˸ü¸´ÔӵĿØÖÆÀ´½â¾öÕâЩÎÊÌâ¡£ ReentrantLock ÀàʵÏÖÁË Lock£¬ËüÓµÓÐÓë synchronized ÏàͬµÄ²¢·¢ÐÔºÍÄÚ´æÓïÒåÇÒËü»¹¾ßÓпÉÀ©Õ¹ÐÔ¡£Äã¿ÉÒԲ鿴ÕâƪÎÄÕÂÁ˽â¸ü¶à
33) ÓÐÈý¸öÏß³ÌT1£¬T2£¬T3£¬Ôõôȷ±£ËüÃÇ°´Ë³ÐòÖ´ÐÐ?
ÔÚ¶àÏß³ÌÖÐÓжàÖÖ·½·¨ÈÃḬ̈߳´Ìض¨Ë³ÐòÖ´ÐУ¬Äã¿ÉÒÔÓÃÏß³ÌÀàµÄjoin()·½·¨ÔÚÒ»¸öÏß³ÌÖÐÆô¶¯ÁíÒ»¸öỊ̈߳¬ÁíÍâÒ»¸öÏß³ÌÍê³É¸ÃÏ̼߳ÌÐøÖ´ÐС£ÎªÁËÈ·±£Èý¸öÏ̵߳Ä˳ÐòÄãÓ¦¸ÃÏÈÆô¶¯×îºóÒ»¸ö(T3µ÷ÓÃT2£¬T2µ÷ÓÃT1)£¬ÕâÑùT1¾Í»áÏÈÍê³É¶øT3×îºóÍê³É¡£Äã¿ÉÒԲ鿴ÕâƪÎÄÕÂÁ˽â¸ü¶à¡£
34) ThreadÀàÖеÄyield·½·¨ÓÐʲô×÷ÓÃ?
Yield·½·¨¿ÉÒÔÔÝÍ£µ±Ç°ÕýÔÚÖ´ÐеÄÏ̶߳ÔÏó£¬ÈÃÆäËüÓÐÏàͬÓÅÏȼ¶µÄÏß³ÌÖ´ÐС£ËüÊÇÒ»¸ö¾²Ì¬·½·¨¶øÇÒÖ»±£Ö¤µ±Ç°Ï̷߳ÅÆúCPUÕ¼Óöø²»Äܱ£Ö¤Ê¹ÆäËüÏß³ÌÒ»¶¨ÄÜÕ¼ÓÃCPU£¬Ö´ÐÐyield()µÄÏß³ÌÓпÉÄÜÔÚ½øÈëµ½ÔÝͣ״̬ºóÂíÉÏÓÖ±»Ö´ÐС£µã»÷ÕâÀï²é¿´¸ü¶àyield·½·¨µÄÏà¹ØÄÚÈÝ¡£
35) JavaÖÐConcurrentHashMapµÄ²¢·¢¶ÈÊÇʲô?
ConcurrentHashMap°Ñʵ¼Êmap»®·Ö³ÉÈô¸É²¿·ÖÀ´ÊµÏÖËüµÄ¿ÉÀ©Õ¹ÐÔºÍḬ̈߳²È«¡£ÕâÖÖ»®·ÖÊÇʹÓò¢·¢¶È»ñµÃµÄ£¬ËüÊÇConcurrentHashMapÀ๹Ô캯ÊýµÄÒ»¸ö¿ÉÑ¡²ÎÊý£¬Ä¬ÈÏֵΪ16£¬ÕâÑùÔÚ¶àÏß³ÌÇé¿öϾÍÄܱÜÃâÕùÓá£ÓûÁ˽â¸ü¶à²¢·¢¶ÈºÍÄÚ²¿´óСµ÷ÕûÇëÔĶÁÎÒµÄÎÄÕÂHow ConcurrentHashMap works in Java¡£
36) JavaÖÐSemaphoreÊÇʲô?
JavaÖеÄSemaphoreÊÇÒ»ÖÖеÄͬ²½À࣬ËüÊÇÒ»¸ö¼ÆÊýÐźš£´Ó¸ÅÄîÉϽ²£¬´Ó¸ÅÄîÉϽ²£¬ÐźÅÁ¿Î¬»¤ÁËÒ»¸öÐí¿É¼¯ºÏ¡£ÈçÓбØÒª£¬ÔÚÐí¿É¿ÉÓÃÇ°»á×èÈûÿһ¸ö acquire()£¬È»ºóÔÙ»ñÈ¡¸ÃÐí¿É¡£Ã¿¸ö release()Ìí¼ÓÒ»¸öÐí¿É£¬´Ó¶ø¿ÉÄÜÊÍ·ÅÒ»¸öÕýÔÚ×èÈûµÄ»ñÈ¡Õß¡£µ«ÊÇ£¬²»Ê¹ÓÃʵ¼ÊµÄÐí¿É¶ÔÏó£¬SemaphoreÖ»¶Ô¿ÉÓÃÐí¿ÉµÄºÅÂë½øÐмÆÊý£¬²¢²ÉÈ¡ÏàÓ¦µÄÐж¯¡£ÐźÅÁ¿³£³£ÓÃÓÚ¶àÏ̵߳ĴúÂëÖУ¬±ÈÈçÊý¾Ý¿âÁ¬½Ó³Ø¡£¸ü¶àÏêϸÐÅÏ¢Çëµã»÷ÕâÀï¡£
37)Èç¹ûÄãÌá½»ÈÎÎñʱ£¬Ï̳߳ضÓÁÐÒÑÂú¡£»áʱ·¢»áÉúʲô?
Õâ¸öÎÊÌâÎʵúܽƻ«£¬Ðí¶à³ÌÐòÔ±»áÈÏΪ¸ÃÈÎÎñ»á×èÈûÖ±µ½Ï̳߳ضÓÁÐÓпÕλ¡£ÊÂʵÉÏÈç¹ûÒ»¸öÈÎÎñ²»Äܱ»µ÷¶ÈÖ´ÐÐÄÇôThreadPoolExecutor¡¯s submit()·½·¨½«»áÅ׳öÒ»¸öRejectedExecutionExceptionÒì³£¡£
38) JavaÏ̳߳ØÖÐsubmit() ºÍ execute()·½·¨ÓÐʲôÇø±ð?
Á½¸ö·½·¨¶¼¿ÉÒÔÏòÏ̳߳ØÌá½»ÈÎÎñ£¬execute()·½·¨µÄ·µ»ØÀàÐÍÊÇvoid£¬Ëü¶¨ÒåÔÚExecutor½Ó¿ÚÖÐ, ¶øsubmit()·½·¨¿ÉÒÔ·µ»Ø³ÖÓмÆËã½á¹ûµÄFuture¶ÔÏó£¬Ëü¶¨ÒåÔÚExecutorService½Ó¿ÚÖУ¬ËüÀ©Õ¹ÁËExecutor½Ó¿Ú£¬ÆäËüÏ̳߳ØÀàÏñThreadPoolExecutorºÍScheduledThreadPoolExecutor¶¼ÓÐÕâЩ·½·¨¡£¸ü¶àÏêϸÐÅÏ¢Çëµã»÷ÕâÀï¡£
39) ʲôÊÇ×èÈûʽ·½·¨?
×èÈûʽ·½·¨ÊÇÖ¸³ÌÐò»áÒ»Ö±µÈ´ý¸Ã·½·¨Íê³ÉÆڼ䲻×öÆäËûÊÂÇ飬ServerSocketµÄaccept()·½·¨¾ÍÊÇÒ»Ö±µÈ´ý¿Í»§¶ËÁ¬½Ó¡£ÕâÀïµÄ×èÈûÊÇÖ¸µ÷Óýá¹û·µ»Ø֮ǰ£¬µ±Ç°Ï̻߳ᱻ¹ÒÆð£¬Ö±µ½µÃµ½½á¹ûÖ®ºó²Å»á·µ»Ø¡£´ËÍ⣬»¹ÓÐÒì²½ºÍ·Ç×èÈûʽ·½·¨ÔÚÈÎÎñÍê³ÉÇ°¾Í·µ»Ø¡£¸ü¶àÏêϸÐÅÏ¢Çëµã»÷ÕâÀï¡£
40) SwingÊÇḬ̈߳²È«µÄÂð? Ϊʲô?
Äã¿ÉÒԺܿ϶¨µÄ¸ø³ö»Ø´ð£¬Swing²»ÊÇḬ̈߳²È«µÄ£¬µ«ÊÇÄãÓ¦¸Ã½âÊÍÕâô»Ø´ðµÄÔÒò¼´±ãÃæÊÔ¹ÙûÓÐÎÊÄãΪʲô¡£µ±ÎÒÃÇ˵swing²»ÊÇḬ̈߳²È«µÄ³£³£Ìáµ½ËüµÄ×é¼þ£¬ÕâЩ×é¼þ²»ÄÜÔÚ¶àÏß³ÌÖнøÐÐÐ޸ģ¬ËùÓжÔGUI×é¼þµÄ¸üж¼ÒªÔÚAWTÏß³ÌÖÐÍê³É£¬¶øSwingÌṩÁËͬ²½ºÍÒì²½Á½Öֻص÷·½·¨À´½øÐиüС£µã»÷ÕâÀï²é¿´¸ü¶àswingºÍḬ̈߳²È«µÄÏà¹ØÄÚÈÝ¡£
41) JavaÖÐinvokeAndWait ºÍ invokeLaterÓÐʲôÇø±ð?
ÕâÁ½¸ö·½·¨ÊÇSwing API Ìṩ¸øJava¿ª·¢ÕßÓÃÀ´´Óµ±Ç°Ï̶߳ø²»ÊÇʼþÅÉ·¢Ï̸߳üÐÂGUI×é¼þÓõġ£InvokeAndWait()ͬ²½¸üÐÂGUI×é¼þ£¬±ÈÈçÒ»¸ö½ø¶ÈÌõ£¬Ò»µ©½ø¶È¸üÐÂÁË£¬½ø¶ÈÌõÒ²Òª×ö³öÏàÓ¦¸Ä±ä¡£Èç¹û½ø¶È±»¶à¸öÏ̸߳ú×Ù£¬ÄÇô¾Íµ÷ÓÃinvokeAndWait()·½·¨ÇëÇóʼþÅÉ·¢Ï̶߳Ô×é¼þ½øÐÐÏàÓ¦¸üС£¶øinvokeLater()·½·¨ÊÇÒì²½µ÷ÓøüÐÂ×é¼þµÄ¡£¸ü¶àÏêϸÐÅÏ¢Çëµã»÷ÕâÀï¡£
42) Swing APIÖÐÄÇЩ·½·¨ÊÇḬ̈߳²È«µÄ?
Õâ¸öÎÊÌâÓÖÌáµ½ÁËswingºÍḬ̈߳²È«£¬ËäÈ»×é¼þ²»ÊÇḬ̈߳²È«µÄµ«ÊÇÓÐһЩ·½·¨ÊÇ¿ÉÒÔ±»¶àḬ̈߳²È«µ÷Óõģ¬±ÈÈçrepaint(), revalidate()¡£ JTextComponentµÄsetText()·½·¨ºÍJTextAreaµÄ() ºÍ append() ·½·¨Ò²ÊÇḬ̈߳²È«µÄ¡£
43) ÈçºÎÔÚJavaÖд´½¨Immutable¶ÔÏó?
Õâ¸öÎÊÌâ¿´ÆðÀ´ºÍ¶àÏß³Ìûʲô¹Øϵ£¬ µ«²»±äÐÔÓÐÖúÓÚ¼ò»¯ÒѾºÜ¸´ÔӵIJ¢·¢³ÌÐò¡£Immutable¶ÔÏó¿ÉÒÔÔÚûÓÐͬ²½µÄÇé¿öϹ²Ïí£¬½µµÍÁ˶ԸöÔÏó½øÐв¢·¢·ÃÎÊʱµÄͬ²½»¯¿ªÏú¡£¿ÉÊÇJavaûÓÐ@ImmutableÕâ¸ö×¢½â·û£¬Òª´´½¨²»¿É±äÀ࣬ҪʵÏÖÏÂÃ漸¸ö²½Ö裺ͨ¹ý¹¹Ôì·½·¨³õʼ»¯ËùÓгÉÔ±¡¢¶Ô±äÁ¿²»ÒªÌṩsetter·½·¨¡¢½«ËùÓеijÉÔ±ÉùÃ÷Ϊ˽Óеģ¬ÕâÑù¾Í²»ÔÊÐíÖ±½Ó·ÃÎÊÕâЩ³ÉÔ±¡¢ÔÚgetter·½·¨ÖУ¬²»ÒªÖ±½Ó·µ»Ø¶ÔÏó±¾Éí£¬¶øÊÇ¿Ë¡¶ÔÏ󣬲¢·µ»Ø¶ÔÏóµÄ¿½±´¡£ÎÒµÄÎÄÕÂhow to make an object Immutable in JavaÓÐÏêϸµÄ½Ì³Ì£¬¿´ÍêÄã¿ÉÒÔ³äÂú×ÔÐÅ¡£
44) JavaÖеÄReadWriteLockÊÇʲô?
Ò»°ã¶øÑÔ£¬¶ÁдËøÊÇÓÃÀ´ÌáÉý²¢·¢³ÌÐòÐÔÄܵÄËø·ÖÀë¼¼ÊõµÄ³É¹û¡£JavaÖеÄReadWriteLockÊÇJava 5 ÖÐÐÂÔöµÄÒ»¸ö½Ó¿Ú£¬Ò»¸öReadWriteLockά»¤Ò»¶Ô¹ØÁªµÄËø£¬Ò»¸öÓÃÓÚÖ»¶Á²Ù×÷Ò»¸öÓÃÓÚд¡£ÔÚûÓÐдÏ̵߳ÄÇé¿öÏÂÒ»¸ö¶ÁËø¿ÉÄÜ»áͬʱ±»¶à¸ö¶ÁÏ̳߳ÖÓС£Ð´ËøÊǶÀÕ¼µÄ£¬Äã¿ÉÒÔʹÓÃJDKÖеÄReentrantReadWriteLockÀ´ÊµÏÖÕâ¸ö¹æÔò£¬Ëü×î¶àÖ§³Ö65535¸öдËøºÍ65535¸ö¶ÁËø¡£
45) ¶àÏß³ÌÖеÄæѻ·ÊÇʲô?
æѻ·¾ÍÊdzÌÐòÔ±ÓÃÑ»·ÈÃÒ»¸öÏ̵߳ȴý£¬²»Ïñ´«Í³·½·¨wait(), sleep() »ò yield() ËüÃǶ¼·ÅÆúÁËCPU¿ØÖÆ£¬¶øæѻ·²»»á·ÅÆúCPU£¬Ëü¾ÍÊÇÔÚÔËÐÐÒ»¸ö¿ÕÑ»·¡£Õâô×öµÄÄ¿µÄÊÇΪÁ˱£ÁôCPU»º´æ£¬ÔÚ¶àºËϵͳÖУ¬Ò»¸öµÈ´ýÏß³ÌÐÑÀ´µÄʱºò¿ÉÄÜ»áÔÚÁíÒ»¸öÄÚºËÔËÐУ¬ÕâÑù»áÖؽ¨»º´æ¡£ÎªÁ˱ÜÃâÖؽ¨»º´æºÍ¼õÉٵȴýÖؽ¨µÄʱ¼ä¾Í¿ÉÒÔʹÓÃËüÁË¡£Äã¿ÉÒԲ鿴ÕâƪÎÄÕ»ñµÃ¸ü¶àÐÅÏ¢¡£
46)volatile ±äÁ¿ºÍ atomic ±äÁ¿ÓÐʲô²»Í¬?
ÕâÊǸöÓÐȤµÄÎÊÌâ¡£Ê×ÏÈ£¬volatile ±äÁ¿ºÍ atomic ±äÁ¿¿´ÆðÀ´ºÜÏñ£¬µ«¹¦ÄÜÈ´²»Ò»Ñù¡£Volatile±äÁ¿¿ÉÒÔÈ·±£ÏÈÐйØϵ£¬¼´Ð´²Ù×÷»á·¢ÉúÔÚºóÐøµÄ¶Á²Ù×÷֮ǰ, µ«Ëü²¢²»Äܱ£Ö¤Ô×ÓÐÔ¡£ÀýÈçÓÃvolatileÐÞÊÎcount±äÁ¿ÄÇô count ²Ù×÷¾Í²»ÊÇÔ×ÓÐԵġ£¶øAtomicIntegerÀàÌṩµÄatomic·½·¨¿ÉÒÔÈÃÕâÖÖ²Ù×÷¾ßÓÐÔ×ÓÐÔÈçgetAndIncrement()·½·¨»áÔ×ÓÐԵĽøÐÐÔöÁ¿²Ù×÷°Ñµ±Ç°Öµ¼ÓÒ»£¬ÆäËüÊý¾ÝÀàÐͺÍÒýÓñäÁ¿Ò²¿ÉÒÔ½øÐÐÏàËƲÙ×÷¡£
47) Èç¹ûͬ²½¿éÄÚµÄÏß³ÌÅ׳öÒì³£»á·¢Éúʲô?
Õâ¸öÎÊÌâ¿ÓÁ˺ܶàJava³ÌÐòÔ±£¬ÈôÄãÄÜÏëµ½ËøÊÇ·ñÊÍ·ÅÕâÌõÏßË÷À´»Ø´ð»¹ÓеãÏ£Íû´ð¶Ô¡£ÎÞÂÛÄãµÄͬ²½¿éÊÇÕý³£»¹ÊÇÒì³£Í˳öµÄ£¬ÀïÃæµÄÏ̶߳¼»áÊÍ·ÅËø£¬ËùÒÔ¶Ô±ÈËø½Ó¿ÚÎÒ¸üϲ»¶Í¬²½¿é£¬ÒòΪËü²»ÓÃÎÒ»¨·Ñ¾«Á¦È¥ÊÍ·ÅËø£¬¸Ã¹¦ÄÜ¿ÉÒÔÔÚfinally blockÀïÊÍ·ÅËøʵÏÖ¡£
48) µ¥ÀýģʽµÄË«¼ìËøÊÇʲô?
Õâ¸öÎÊÌâÔÚJavaÃæÊÔÖо³£±»Îʵ½£¬µ«ÊÇÃæÊԹٶԻشð´ËÎÊÌâµÄÂúÒâ¶È½öΪ50%¡£Ò»°ëµÄÈËд²»³öË«¼ìËø»¹ÓÐÒ»°ëµÄÈË˵²»³öËüµÄÒþ»¼ºÍJava1.5ÊÇÈçºÎ¶ÔËüÐÞÕýµÄ¡£ËüÆäʵÊÇÒ»¸öÓÃÀ´´´½¨Ḭ̈߳²È«µÄµ¥ÀýµÄÀÏ·½·¨£¬µ±µ¥ÀýʵÀýµÚÒ»´Î±»´´½¨Ê±ËüÊÔͼÓõ¥¸öËø½øÐÐÐÔÄÜÓÅ»¯£¬µ«ÊÇÓÉÓÚÌ«¹ýÓÚ¸´ÔÓÔÚJDK1.4ÖÐËüÊÇʧ°ÜµÄ£¬ÎÒ¸öÈËÒ²²»Ï²»¶Ëü¡£ÎÞÂÛÈçºÎ£¬¼´±ãÄãÒ²²»Ï²»¶Ëüµ«ÊÇ»¹ÊÇÒªÁ˽âһϣ¬ÒòΪËü¾³£±»Îʵ½¡£Äã¿ÉÒԲ鿴how double checked locking on Singleton worksÕâƪÎÄÕ»ñµÃ¸ü¶àÐÅÏ¢¡£
49) ÈçºÎÔÚJavaÖд´½¨Ḭ̈߳²È«µÄSingleton?
ÕâÊÇÉÏÃæÄǸöÎÊÌâµÄºóÐø£¬Èç¹ûÄ㲻ϲ»¶Ë«¼ìËø¶øÃæÊÔ¹ÙÎÊÁË´´½¨SingletonÀàµÄÌæ´ú·½·¨£¬Äã¿ÉÒÔÀûÓÃJVMµÄÀà¼ÓÔغ;²Ì¬±äÁ¿³õʼ»¯ÌØÕ÷À´´´½¨SingletonʵÀý£¬»òÕßÊÇÀûÓÃö¾ÙÀàÐÍÀ´´´½¨Singleton£¬ÎÒºÜϲ»¶ÓÃÕâÖÖ·½·¨¡£Äã¿ÉÒԲ鿴ÕâƪÎÄÕ»ñµÃ¸ü¶àÐÅÏ¢¡£
50) д³ö3ÌõÄã×ñѵĶàÏß³Ì×î¼Ñʵ¼ù
ÕâÖÖÎÊÌâÎÒ×îϲ»¶ÁË£¬ÎÒÏàÐÅÄãÔÚд²¢·¢´úÂëÀ´ÌáÉýÐÔÄܵÄʱºòÒ²»á×ñÑijЩ×î¼Ñʵ¼ù¡£ÒÔÏÂÈýÌõ×î¼Ñʵ¼ùÎÒ¾õµÃ´ó¶àÊýJava³ÌÐòÔ±¶¼Ó¦¸Ã×ñÑ£º
¸øÄãµÄÏß³ÌÆð¸öÓÐÒâÒåµÄÃû×Ö¡£
ÕâÑù¿ÉÒÔ·½±ãÕÒbug»ò×·×Ù¡£OrderProcessor, QuoteProcessor or TradeProcessor ÕâÖÖÃû×Ö±È Thread-1. Thread-2 and Thread-3 ºÃ¶àÁË£¬¸øÏß³ÌÆðÒ»¸öºÍËüÒªÍê³ÉµÄÈÎÎñÏà¹ØµÄÃû×Ö£¬ËùÓеÄÖ÷Òª¿ò¼ÜÉõÖÁJDK¶¼×ñÑÕâ¸ö×î¼Ñʵ¼ù¡£
±ÜÃâËø¶¨ºÍËõСͬ²½µÄ·¶Î§
Ëø»¨·ÑµÄ´ú¼Û¸ß°ºÇÒÉÏÏÂÎÄÇл»¸üºÄ·Ñʱ¼ä¿Õ¼ä£¬ÊÔÊÔ×îµÍÏ޶ȵÄʹÓÃͬ²½ºÍËø£¬ËõСÁÙ½çÇø¡£Òò´ËÏà¶ÔÓÚͬ²½·½·¨ÎÒ¸üϲ»¶Í¬²½¿é£¬Ëü¸øÎÒÓµÓжÔËøµÄ¾ø¶Ô¿ØÖÆȨ¡£
¶àÓÃͬ²½ÀàÉÙÓÃwait ºÍ notify
Ê×ÏÈ£¬CountDownLatch, Semaphore, CyclicBarrier ºÍ Exchanger ÕâЩͬ²½Àà¼ò»¯Á˱àÂë²Ù×÷£¬¶øÓÃwaitºÍnotifyºÜÄÑʵÏÖ¶Ô¸´ÔÓ¿ØÖÆÁ÷µÄ¿ØÖÆ¡£Æä´Î£¬ÕâЩÀàÊÇÓÉ×îºÃµÄÆóÒµ±àдºÍά»¤ÔÚºóÐøµÄJDKÖÐËüÃÇ»¹»á²»¶ÏÓÅ»¯ºÍÍêÉÆ£¬Ê¹ÓÃÕâЩ¸ü¸ßµÈ¼¶µÄͬ²½¹¤¾ßÄãµÄ³ÌÐò¿ÉÒÔ²»·Ñ´µ»ÒÖ®Á¦»ñµÃÓÅ»¯¡£
¶àÓò¢·¢¼¯ºÏÉÙÓÃͬ²½¼¯ºÏ
ÕâÊÇÁíÍâÒ»¸öÈÝÒ××ñÑÇÒÊÜÒæ¾Þ´óµÄ×î¼Ñʵ¼ù£¬²¢·¢¼¯ºÏ±Èͬ²½¼¯ºÏµÄ¿ÉÀ©Õ¹ÐÔ¸üºÃ£¬ËùÒÔÔÚ²¢·¢±à³ÌʱʹÓò¢·¢¼¯ºÏЧ¹û¸üºÃ¡£Èç¹ûÏÂÒ»´ÎÄãÐèÒªÓõ½map£¬ÄãÓ¦¸ÃÊ×ÏÈÏëµ½ÓÃConcurrentHashMap¡£ÎÒµÄÎÄÕÂJava²¢·¢¼¯ºÏÓиüÏêϸµÄ˵Ã÷¡£
51) ÈçºÎÇ¿ÖÆÆô¶¯Ò»¸öÏß³Ì?
Õâ¸öÎÊÌâ¾ÍÏñÊÇÈçºÎÇ¿ÖƽøÐÐJavaÀ¬»ø»ØÊÕ£¬Ä¿Ç°»¹Ã»ÓоõµÃ·½·¨£¬ËäÈ»Äã¿ÉÒÔʹÓÃSystem.gc()À´½øÐÐÀ¬»ø»ØÊÕ£¬µ«ÊDz»±£Ö¤Äܳɹ¦¡£ÔÚJavaÀïÃæûÓа취ǿÖÆÆô¶¯Ò»¸öỊ̈߳¬ËüÊDZ»Ï̵߳÷¶ÈÆ÷¿ØÖÆ×ÅÇÒJavaûÓй«²¼Ïà¹ØµÄAPI¡£
52) JavaÖеÄfork join¿ò¼ÜÊÇʲô?
fork join¿ò¼ÜÊÇJDK7ÖгöÏÖµÄÒ»¿î¸ßЧµÄ¹¤¾ß£¬Java¿ª·¢ÈËÔ±¿ÉÒÔͨ¹ýËü³ä·ÖÀûÓÃÏÖ´ú·þÎñÆ÷ÉϵĶദÀíÆ÷¡£ËüÊÇרÃÅΪÁËÄÇЩ¿ÉÒԵݹ黮·Ö³ÉÐí¶à×ÓÄ£¿éÉè¼ÆµÄ£¬Ä¿µÄÊǽ«ËùÓпÉÓõĴ¦ÀíÄÜÁ¦ÓÃÀ´ÌáÉý³ÌÐòµÄÐÔÄÜ¡£fork join¿ò¼ÜÒ»¸ö¾Þ´óµÄÓÅÊÆÊÇËüʹÓÃÁ˹¤×÷ÇÔÈ¡Ëã·¨£¬¿ÉÒÔÍê³É¸ü¶àÈÎÎñµÄ¹¤×÷Ï߳̿ÉÒÔ´ÓÆäËüÏß³ÌÖÐÇÔÈ¡ÈÎÎñÀ´Ö´ÐС£Äã¿ÉÒԲ鿴ÕâƪÎÄÕ»ñµÃ¸ü¶àÐÅÏ¢¡£
53) Java¶àÏß³ÌÖе÷ÓÃwait() ºÍ sleep()·½·¨ÓÐʲô²»Í¬?
Java³ÌÐòÖÐwait ºÍ sleep¶¼»áÔì³ÉijÖÖÐÎʽµÄÔÝÍ££¬ËüÃÇ¿ÉÒÔÂú×㲻ͬµÄÐèÒª¡£wait()·½·¨ÓÃÓÚÏ̼߳äͨÐÅ£¬Èç¹ûµÈ´ýÌõ¼þΪÕæÇÒÆäËüÏ̱߳»»½ÐÑʱËü»áÊÍ·ÅËø£¬¶øsleep()·½·¨½ö½öÊÍ·ÅCPU×ÊÔ´»òÕßÈõ±Ç°Ïß³ÌÍ£Ö¹Ö´ÐÐÒ»¶Îʱ¼ä£¬µ«²»»áÊÍ·ÅËø¡£