ΪʲôҪʹÓÃÏ̳߳أ¿

2018-10-24 08:45:06À´Ô´£º²©¿ÍÔ° ÔĶÁ ()

ÐÂÀÏ¿Í»§´ó»ØÀ¡,ÔÆ·þÎñÆ÷µÍÖÁ5ÕÛ

ΪÁ˼õÉÙ´´½¨ºÍÏú»ÙÏ̵߳ĴÎÊý£¬ÈÃÿ¸öÏ߳̿ÉÒÔ¶à´ÎʹÓÃ,¿É¸ù¾ÝϵͳÇé¿öµ÷ÕûÖ´ÐеÄÏß³ÌÊýÁ¿£¬·ÀÖ¹ÏûºÄ¹ý¶àÄÚ´æ,ËùÒÔÎÒÃÇ¿ÉÒÔʹÓÃÏ̳߳Ø.

javaÖÐÏ̳߳صĶ¥¼¶½Ó¿ÚÊÇExecutor(e¿Érai kei ter)£¬ExecutorServiceÊÇExecutorµÄ×ÓÀ࣬ҲÊÇÕæÕýµÄÏ̳߳ؽӿڣ¬ËüÌṩÁËÌá½»ÈÎÎñºÍ¹Ø±ÕÏ̳߳صȷ½·¨¡£µ÷ÓÃsubmit·½·¨Ìá½»ÈÎÎñ»¹¿ÉÒÔ·µ»ØÒ»¸öFuture(fei Çú¶ù)¶ÔÏó£¬ÀûÓøöÔÏó¿ÉÒÔÁ˽âÈÎÎñÖ´ÐÐÇé¿ö£¬»ñµÃÈÎÎñµÄÖ´Ðнá¹û»òÈ¡ÏûÈÎÎñ¡£

ÓÉÓÚÏ̳߳صÄÅäÖñȽϸ´ÔÓ£¬JavaSEÖж¨ÒåÁËExecutorsÀà¾ÍÊÇÓÃÀ´·½±ã´´½¨¸÷ÖÖ³£ÓÃÏ̳߳صŤ¾ßÀࡣͨ¹ýµ÷Óøù¤¾ßÀàÖеķ½·¨ÎÒÃÇ¿ÉÒÔ´´½¨µ¥Ï̳߳Ø(newSingleThreadExecutor),¹Ì¶¨ÊýÁ¿µÄÏ̳߳Ø(newFixedThreadPool)£¬¿É»º´æÏ̳߳Ø(newCachedThreadPool),´óСÎÞÏÞÖƵÄÏ̳߳Ø(newScheduledThreadPool),±È½Ï³£ÓõÄÊǹ̶¨ÊýÁ¿µÄÏ̳߳غͿɻº´æµÄÏ̳߳Ø,¹Ì¶¨ÊýÁ¿µÄÏ̳߳ØÊÇÿÌá½»Ò»¸öÈÎÎñ¾ÍÊÇÒ»¸öỊ̈߳¬Ö±µ½´ïµ½Ï̳߳صÄ×î´óÊýÁ¿£¬È»ºóºóÃæ½øÈëµÈ´ý¶ÓÁÐÖ±µ½Ç°ÃæµÄÈÎÎñÍê³É²Å¼ÌÐøÖ´ÐÐ.¿É»º´æÏ̳߳ØÊǵ±Ï̳߳شóС³¬¹ýÁË´¦ÀíÈÎÎñËùÐèµÄỊ̈߳¬ÄÇô¾Í»á»ØÊÕ²¿·Ö¿ÕÏУ¨Ò»°ãÊÇ60ÃëÎÞÖ´ÐУ©µÄỊ̈߳¬µ±ÓÐÈÎÎñÀ´Ê±£¬ÓÖÖÇÄܵÄÌí¼ÓÐÂÏß³ÌÀ´Ö´ÐÐ.

 

ExecutorsÀàÖл¹¶¨ÒåÁ˼¸¸öÏ̳߳ØÖØÒªµÄ²ÎÊý,±ÈÈç˵int corePoolSizeºËÐijصĴóС,Ò²¾ÍÊÇÏ̳߳ØÖлáά³Ö²»±»ÊͷŵÄÏß³ÌÊýÁ¿.int maximumPoolSizeÏ̳߳صÄ×î´óÏß³ÌÊý£¬´ú±íÕâÏ̳߳ػã×ÜÄÜ´´½¨¶àÉÙÏ̡߳£corePoolSize :ºËÐÄÏß³ÌÊý£¬Èç¹ûÔËÐеÄÏß³ÌÊýÉÙcorePoolSize£¬µ±ÓÐеÄÈÎÎñ¹ýÀ´Ê±»á´´½¨ÐµÄÏß³ÌÀ´Ö´ÐÐÕâ¸öÈÎÎñ£¬¼´Ê¹Ï̳߳ØÖÐÓÐÆäËûµÄ¿ÕÏеÄÏ̡߳£maximumPoolSize:Ï̳߳ØÖÐÔÊÐíµÄ×î´óÏß³ÌÊý.

±êÇ©£º

°æȨÉêÃ÷£º±¾Õ¾ÎÄÕ²¿·Ö×ÔÍøÂ磬ÈçÓÐÇÖȨ£¬ÇëÁªÏµ£ºwest999com@outlook.com
Ìرð×¢Ò⣺±¾Õ¾ËùÓÐתÔØÎÄÕÂÑÔÂÛ²»´ú±í±¾Õ¾¹Ûµã£¬±¾Õ¾ËùÌṩµÄÉãÓ°ÕÕƬ£¬²å»­£¬Éè¼Æ×÷Æ·£¬ÈçÐèʹÓã¬ÇëÓëÔ­×÷ÕßÁªÏµ£¬°æȨ¹éÔ­×÷ÕßËùÓÐ

ÉÏһƪ£ºspring-AOP£¨ÃæÏòÇÐÃæ±à³Ì)-xml·½Ê½ÅäÖÃ

ÏÂһƪ£ºJNI ¼Ç