¼ò½éAcceptor¹ËÃû˼Òå¾ÍÊǽÓÊÕÆ÷£¬ÓÃÓÚ½ÓÊÕÓû§ÇëÇó£¬Õâ½ÚÖ÷ÒªÊÇ·ÖÎöAcceptorµÄÆô¶¯ºÍ´¦ÀíÇëÇó£¡ Ê×ÏÈÀ´¿´AcceptorµÄÀàͼ
´ÓͼÖпÉÒÔ¿´³öAcceptorʵÏÖÁËRunnable½Ó¿Ú£¬¿ÉÒÔ×÷Ϊһ¸öÏß³ÌÆô¶¯£¬ÇÒ¶¼ÊÇEndpointµÄÄÚ²¿Àà¡£AcceptorÓÐ3ÖÖʵÏÖJIo¡¢Apr¡¢Nio±¾½Ú²»»á½éÉÜËûÃÇÖ®¼äµÄÇø±ð£¬³£ÓõÄÊÇJIoEndpoint.Acceptor£¬ºóÃæµÄÀý×Ó£¬Èç¹ûûÓÐ×öÌرð˵Ã÷Ö¸µÄÊÇJIoEndpointÀàÀïÃæµÄ½ÓÊÕÆ÷¡£
Æô¶¯
ÔÚtomcatÆô¶¯µÄʱºò»áÆô¶¯Endpoint,»áµ÷ÓÃËüµÄstartInternal·½·¨£¬À´¿´¿´Õâ¸ö·½·¨×öÁËÄÄЩÊ£º
2¡¢Æô¶¯´øÓнÓÊÕÆ÷µÄÏß³Ì
(1)getAcceptorThreadCount£ºÔÚendpoint³õʼ»¯Ê±£¬µ÷ÓÃAbstractEndpoint.init·½·¨£¬½ô½Ó×ŵ÷ÓÃbind·½·¨£¬ÊµÏÖÊÇÔÚ×ÓÀàʵÏֵģ¬¿´¿´JIOEndpointÀàµÄ bind·½·¨
(2)È»ºó´´½¨count¸öỊ̈߳¬Ã¿¸öÏß³ÌÉ϶¼´øÓÐÒ»¸ö½ÓÊÕÆ÷£¬²¢°ÑÕâЩÏß³ÌÉèÖÃΪºǫ́Ị̈߳¬×îºóÆô¶¯ÕâЩÏß³Ì
´¦ÀíÇëÇóÏÂÃæ¿´¿´Æô¶¯ÕâЩÏ̺߳ó£¬ÕâЩÏß³Ì×öÁËÄÄЩÊ£¿ ÓÉÓÚorg.apache.tomcat.util.net.AbstractEndpoint.AcceptorʵÏÖÁËrunnable½Ó¿Ú£¬Æô¶¯ÕâЩỊ̈߳¬Ò²¾ÍÊÇÔËÐÐ org.apache.tomcat.util.net.AbstractEndpoint.AcceptorʵÏÖÀàµÄrun·½·¨£¬»¹ÊÇÒÔJIOµÄʵÏÖ·½Ê½ÎªÀýÀ´¿´£¬ÒÔÏ´úÂëÊ¡ÂÔÁ˺ܶàÒì³£´¦Àí
1¡¢ÕûÌåÀ´¿´ÊÇÒ»¸öwhileÑ»·£¬Ö»Òª·þÎñÆ÷ûÓб»¹Ø±Õ£¬Õâ¸öwhileÑ»·»áÒ»Ö±ÔËÐУ¬µ±Ã»ÓÐÇëÇóµ½À´Ê±£¬ÕâЩÏ߳̾ͻásleep 2¡¢»ñÈ¡Ò»¸ö½ÓÁ¬£¬µ×²ãµ÷ÓõÄÊÇAQSµÄsync.acquireSharedInterruptibly(1)·½·¨£¬ÓпÉÄÜÐèÒª×èÈû 3¡¢Èç¹ûÓÐÇëÇóµ½À´¾Í»áµ÷ÓÃserverSocketFactory.acceptSocket·½·¨£¬¸Ã·½·¨²»Ï¸½²£¬µ×²ãµ÷ÓõľÍÊÇsocket.accept()·½·¨ 4¡¢·½·¨µ÷Óóɹ¦¾Í»á·ÖÏíÒ»¸öÏß³ÌÀ´´¦ÀíÕâ´ÎÇëÇ󣬴¦ÀíÇëÇóµÄ´úÂëÔÚprocessSocket·½·¨ÖÐÍê³É£¬ºóÃæ»áϸ½²Õâ¸ö·½·¨ 5¡¢Èç¹ûÔÚ´¦ÀíµÄ¹ý³ÌÖлòÕßÔÚacceptSocketµÄ¹ý³ÌÖÐÓÐÒì³£¶¼»áµ÷ÓÃcountDownConnection·½·¨¼õÉÙÁ¬½ÓÊý£¬Èç¹ûsocket»¹´ò¿ª¾Í¹Ø±Õsocket
²Î¿¼×ÊÁÏTomcatÐÔÄܵ÷У֮Á¬½ÓÆ÷Ä£¿éJIO¡¢APRºÍNIO (ÔðÈα༣ºIT) |