¡¶Java»ù´¡ÈëÃÅ¡·¿ÎºóÏ°Ìâ¼°´ð°¸×ÊÁÏ ÏÂÔر¾ÎÄ

1¡¢µ±ÎÒÃÇ´´½¨Ò»¸öÏ̶߳ÔÏóʱ£¬¸Ã¶ÔÏó±íʾµÄÏ߳̾ÍÁ¢¼´¿ªÊ¼ÔËÐС£´í 2¡¢Èç¹ûǰ̨Ïß³ÌÈ«²¿ËÀÍö£¬ºǫ́Ïß³ÌÒ²»á×Ô¶¯ËÀÍö¡£¶Ô 3¡¢Í¬²½´úÂë¿éÖеÄËø¶ÔÏó¿ÉÒÔÊÇÈÎÒâÀàÐ͵ĶÔÏó¡£¶Ô 4¡¢¾²Ì¬·½·¨²»ÄÜʹÓÃsynchronized¹Ø¼ü×ÖÀ´ÐÞÊΡ£´í 5¡¢Ï߳̽áÊøµÈ´ý»òÕß×èÈû״̬ºó£¬»á½øÈëÔËÐÐ״̬¡£´í Èý¡¢Ñ¡ÔñÌâ

1¡¢ThreadÀàλÓÚÏÂÁÐÄĸö°üÖУ¿B

A¡¢java.io B¡¢java.lang C¡¢java.util D¡¢java.awt 2¡¢¹ØÓÚÏ̵߳Ĵ´½¨¹ý³Ì£¬ÏÂÃæËÄÖÖ˵·¨ÕýÈ·µÄÓÐÄÄЩ£¿(¶àÑ¡)AC

A¡¢¶¨ÒåThreadÀàµÄ×ÓÀ࣬ÖØдThreadÀàµÄrun()·½·¨£¬´´½¨¸Ã×ÓÀàµÄʵÀý¶ÔÏ󣬵÷ÓöÔÏóµÄstart()·½·¨

B¡¢¶¨ÒåThreadÀàµÄ×ÓÀ࣬ÖØдThreadÀàµÄrun()·½·¨£¬´´½¨¸Ã×ÓÀàµÄʵÀý¶ÔÏ󣬵÷ÓöÔÏóµÄrun()·½·¨

C¡¢¶¨ÒåÒ»¸öʵÏÖRunnable ½Ó¿ÚµÄÀಢʵÏÖrun()·½·¨£¬´´½¨¸ÃÀàʵÀý¶ÔÏ󣬽«Æä×÷Ϊ²ÎÊý´«µÝ¸øThreadÀàµÄ¹¹Ôì·½·¨À´´´½¨Thread¶ÔÏ󣬵÷ÓÃThread¶ÔÏóµÄstart()·½·¨ D¡¢¶¨ÒåÒ»¸öʵÏÖRunnable ½Ó¿ÚµÄÀಢʵÏÖrun()·½·¨£¬´´½¨¸ÃÀà¶ÔÏó£¬È»ºóµ÷ÓÃrun()·½·¨ 3¡¢¶ÔÓÚͨ¹ýʵÏÖRunnable½Ó¿Ú´´½¨Ị̈߳¬ÏÂÃæ˵·¨ÕýÈ·µÄÓÐÄÄЩ£¿(¶àÑ¡)ABC A¡¢Êʺ϶à¸öÏàͬ³ÌÐò´úÂëµÄÏß³ÌÈ¥´¦Àíͬһ¸ö×ÊÔ´µÄÇé¿ö

B¡¢°ÑÏß³Ìͬ³ÌÐò´úÂë¡¢Êý¾ÝÓÐЧµÄ·ÖÀ룬ºÜºÃµÄÌåÏÖÁËÃæÏò¶ÔÏóµÄÉè¼Æ˼Ïë C¡¢¿ÉÒÔ±ÜÃâÓÉÓÚJavaµÄµ¥¼Ì³Ð´øÀ´µÄ¾ÖÏÞÐÔ D¡¢±àд¼òµ¥£¬¿ÉÒÔ²»Í¨¹ýThreadÀàÖ±½Ó´´½¨Ïß³Ì

4¡¢¶ÔÓÚÏ̵߳ÄÉúÃüÖÜÆÚ£¬ÏÂÃæËÄÖÖ˵·¨ÕýÈ·µÄÓÐÄÄЩ£¿(¶àÑ¡) ABC(BC)

A¡¢µ÷ÓÃÁËÏ̵߳Ästart()·½·¨£¬¸ÃÏ߳̾ͽøÈëÔËÐÐ״̬ (¾ÍÐ÷£¬»¹Òª»ñµÃCPUʹÓÃȨ)

B¡¢Ï̵߳Ärun()·½·¨ÔËÐнáÊø»ò±»Î´catchµÄInterruptedExceptionµÈÒì³£ÖսᣬÄÇô¸ÃÏ߳̽øÈëËÀÍö״̬

C¡¢Ï߳̽øÈëËÀÍö״̬£¬µ«ÊǸÃÏ̶߳ÔÏóÈÔÈ»ÊÇÒ»¸öThread¶ÔÏó£¬ÔÚûÓб»À¬»ø»ØÊÕÆ÷»ØÊÕ֮ǰÈÔ¿ÉÒÔÏñÒýÓÃÆäËü¶ÔÏóÒ»ÑùÒýÓÃËü

D¡¢Ï߳̽øÈëËÀÍö״̬ºó£¬µ÷ÓÃËüµÄstart()·½·¨ÈÔÈ»¿ÉÒÔÖØÐÂÆô¶¯ 5¡¢¶ÔÓÚËÀËøµÄÃèÊö£¬ÏÂÃæËÄÖÖ˵·¨ÕýÈ·ÓÐÄÄЩ£¿(¶àÑ¡)AB£¨ABD£© A¡¢µ±Á½¸öÏ̻߳¥ÏàµÈ´ý¶Ô·½ÊÍ·Åͬ²½Ëøʱ»á·¢ÉúËÀËø B¡¢JavaÐéÄâ»úûÓмì²âºÍ´¦ÀíËÀËøµÄ´ëÊ© C¡¢Ò»µ©³öÏÖËÀËø£¬³ÌÐò»á·¢ÉúÒì³£

D¡¢´¦ÓÚËÀËø״̬µÄÏ̴߳¦ÓÚ×èÈû״̬£¬ÎÞ·¨¼ÌÐøÔËÐÐ 6¡¢ÏÂÃæËĸöÑ¡ÏîÖУ¬ÄÄЩÊÇÏ߳̽øÈë×èÈû״̬µÄÔ­Òò£¿(¶àÑ¡)ABC A¡¢Ïß³ÌÊÔͼ»ñȡij¸ö¶ÔÏóµÄͬ²½Ëø£¬¶ø¸ÃËø±»ÆäËüÏ̳߳ÖÓÐ B¡¢Ï̵߳÷ÓÃÁËÁíÒ»¸öÏ̵߳Äjoin()·½·¨ C¡¢µ±Ï̵߳÷ÓÃÁËÒ»¸ö×èÈûʽµÄIO·½·¨ D¡¢Ï̵߳÷ÓÃÁËsetDaemon(boolean b)·½·¨

7¡¢Ï̵߳÷ÓÃsleep()·½·¨ºó£¬¸ÃÏ߳̽«½øÈëÒÔÏÂÄÄÖÖ״̬£¿C A¡¢¾ÍÐ÷״̬ B¡¢ÔËÐÐ״̬ C¡¢×èÈû״̬

D¡¢ËÀÍö״̬

8¡¢ÔÚÒÔÏÂÄÄÖÖÇé¿öÏ£¬Ï߳̽øÈë¾ÍÐ÷״̬£¿D A¡¢Ï̵߳÷ÓÃÁËsleep()·½·¨Ê±

B¡¢Ï̵߳÷ÓÃÁËjoin()·½·¨(ÖÕÖ¹)

C¡¢Ï̵߳÷ÓÃÁËyield()·½·¨Ê± D¡¢Ï̵߳÷ÓÃÁËnotify()·½·¨??

9¡¢ÏÂÃæËĸöÑ¡ÏîÖУ¬¶ÔÏß³Ìͬ²½µÄÄ¿µÄÃèÊöÕýÈ·µÄÓÐÄÄЩ£¿(¶àÑ¡)AD(AB)

A¡¢Ëø¶¨×ÊÔ´£¬Ê¹Í¬Ò»Ê±¿ÌÖ»ÓÐÒ»¸öÏß³ÌÈ¥·ÃÎÊËü£¬·ÀÖ¹¶à¸öÏ̲߳Ù×÷ͬһ¸ö×ÊÔ´Òý·¢´íÎó B¡¢Ìá¸ßÏ̵߳ÄÖ´ÐÐЧÂÊ C¡¢ÈÃÏ̶߳ÀÕ¼Ò»¸ö×ÊÔ´

D¡¢Èöà¸öÏß³ÌͬʱʹÓÃÒ»¸ö×ÊÔ´

10¡¢¶ÔÓÚwait()·½·¨£¬ÏÂÃæ˵·¨ÕýÈ·µÄÊÇ£¿(¶àÑ¡)ABCD A¡¢wait()·½·¨µÄµ÷ÓÃÕßÊÇͬ²½Ëø¶ÔÏó B¡¢wait()·½·¨Ê¹Ï߳̽øÈëµÈ´ý״̬

C¡¢µ÷ÓÃͬһËø¶ÔÏóµÄnotify()»ònotifyAll()·½·¨¿ÉÒÔ»½Ðѵ÷ÓÃwait()·½·¨µÈ´ýµÄÏß³Ì D¡¢µ÷ÓÃwait()·½·¨µÄÏ̻߳áÊÍ·Åͬ²½Ëø¶ÔÏó

ËÄ¡¢³ÌÐò·ÖÎöÌâ

ÔĶÁÏÂÃæµÄ³ÌÐò£¬·ÖÎö´úÂëÊÇ·ñÄܱàÒëͨ¹ý£¬Èç¹ûÄܱàÒëͨ¹ý£¬ÇëÁгöÔËÐеĽá¹û¡£Èç¹û²»ÄܱàÒëͨ¹ý£¬Çë˵Ã÷Ô­Òò¡£

1.´úÂëÒ»£º²»ÄÜ£¬RunHandlerûÓм̳ÐThread£¬²»ÄÜÓÃThread´´½¨¶ÔÏó(³ÌÐò²»ÄܱàÒëͨ¹ý£¬ÒòΪRunHandlerÀàûÓÐʵÏÖRunnable½Ó¿Ú£¬Òò´ËRunHandlerµÄʵÀý¶ÔÏó²»ÄÜ×÷Ϊ²ÎÊý´«µÝ¸øThreadµÄ¹¹Ôì·½·¨¡£)

class RunHandler {

public void run(){

System.out.println(\} }

public class Test {

public static void main(String [] args) {

Thread t = new Thread(new RunHandler()); t.start(); }

}

2.´úÂë¶þ£ºthis is run(³ÌÐò²»ÄܱàÒëͨ¹ý£¬ÒòΪThreadµÄ×ÓÀàAÖØдµÄrun()·½·¨µÄ·ÃÎʼ¶±ð²»ÄܵÍÓÚ¸¸Ààrun()·½·¨µÄ¡£·ÃÎʼ¶±ð)

public class A extends Thread{

protected void run() {

System.out.println(\ }

public static void main(String[] args) { }

}

A a = new A(); a.start();

3.´úÂëÈý£ºException(³ÌÐò²»ÄܱàÒëͨ¹ý£¬ÒòΪͬ²½·½·¨Öе÷ÓÃwait()·½·¨µÄ¶ÔÏó±ØÐëΪͬ²½Ëø¶ÔÏó)

public class Test{ }

private Object obj=new Object(); public synchronized void a(){ }

public static void main(String[] args) { }

new Test().a(); try { }

obj.wait()£»¸Äthis.wait() System.out.println(\System.out.println(\

} catch (InterruptedException e) {

4.ΪÁËʹÏÂÃæµÄ³ÌÐòÄܹ»Êä³ö¡°Thread is running¡±£¬ÇëÔÚÔÚ¿Õ¸ñ´¦ÌîÉÏÏàÓ¦µÄ´úÂë¡£

public class B implements Runnable {

public static void main(String[] args) { }

public void run() { }

public void go() { }

start(1);

System.out.println(\Thread t = new Thread(new B());

__t.start()_____________________ //´Ë´¦Ìî¿Õ