javaÏ̳߳ØThreadPoolExecut
JDK1.5ÖеÄÏ̳߳Ø(java.util.concurrent.ThreadPoolExecut
6
ÍƼö
ÔÚ¶àÏ̴߳óʦDoug LeaµÄ¹±Ï×Ï£¬ÔÚJDK1.5ÖмÓÈëÁËÐí¶à¶Ô²¢·¢ÌØÐÔµÄÖ§³Ö£¬ÀýÈ磺Ï̳߳ء£
Ò»¡¢¼ò½é
Ï̳߳ØÀàΪ java.util.concurrent.ThreadPoolExecutor£¬³£Óù¹Ôì·½·¨Îª£º
ThreadPoolExecutor(int corePoolSize, int maximumPoolSize,
long keepAliveTime, TimeUnit unit,
BlockingQueue<Runnable> workQueue,
RejectedExecutionHandler handler)
corePoolSize£º Ï̳߳Øά»¤Ï̵߳Ä×îÉÙÊýÁ¿
maximumPoolSize£ºÏ̳߳Øά»¤Ï̵߳Ä×î´óÊýÁ¿
keepAliveTime£º Ï̳߳Øά»¤Ïß³ÌËùÔÊÐíµÄ¿ÕÏÐʱ¼ä
unit£º Ï̳߳Øά»¤Ïß³ÌËùÔÊÐíµÄ¿ÕÏÐʱ¼äµÄµ¥Î»
workQueue£º Ï̳߳ØËùʹÓõĻº³å¶ÓÁÐ
handler£º Ï̳߳ضԾܾøÈÎÎñµÄ´¦Àí²ßÂÔ
Ò»¸öÈÎÎñͨ¹ý execute(Runnable)·½·¨±»Ìí¼Óµ½Ï̳߳أ¬ÈÎÎñ¾ÍÊÇÒ»¸ö RunnableÀàÐ͵ĶÔÏó£¬ÈÎÎñµÄÖ´Ðз½·¨¾ÍÊÇ RunnableÀàÐͶÔÏóµÄrun()·½·¨¡£
µ±Ò»¸öÈÎÎñͨ¹ýexecute(Runnable)·½·¨ÓûÌí¼Óµ½Ï̳߳Øʱ£º
Èç¹û´ËʱÏ̳߳ØÖеÄÊýÁ¿Ð¡ÓÚcorePoolSize£¬¼´Ê¹Ï̳߳ØÖеÄÏ̶߳¼´¦ÓÚ¿ÕÏÐ״̬£¬Ò²Òª´´½¨ÐµÄÏß³ÌÀ´´¦Àí±»Ìí¼ÓµÄÈÎÎñ¡£
Èç¹û´ËʱÏ̳߳ØÖеÄÊýÁ¿µÈÓÚ corePoolSize£¬µ«ÊÇ»º³å¶ÓÁÐ workQueueδÂú£¬ÄÇôÈÎÎñ±»·ÅÈ뻺³å¶ÓÁС£
Èç¹û´ËʱÏ̳߳ØÖеÄÊýÁ¿´óÓÚcorePoolSize£¬»º³å¶ÓÁÐworkQueueÂú£¬²¢ÇÒÏ̳߳ØÖеÄÊýÁ¿Ð¡ÓÚmaximumPoolSize£¬½¨ÐµÄÏß³ÌÀ´´¦Àí±»Ìí¼ÓµÄÈÎÎñ¡£
Èç¹û´ËʱÏ̳߳ØÖеÄÊýÁ¿´óÓÚcorePoolSize£¬»º³å¶ÓÁÐworkQueueÂú£¬²¢ÇÒÏ̳߳ØÖеÄÊýÁ¿µÈÓÚmaximumPoolSize£¬ÄÇôͨ¹ý handlerËùÖ¸¶¨µÄ²ßÂÔÀ´´¦Àí´ËÈÎÎñ¡£
Ò²¾ÍÊÇ£º´¦ÀíÈÎÎñµÄÓÅÏȼ¶Îª£º
ºËÐÄÏß³ÌcorePoolSize¡¢ÈÎÎñ¶ÓÁÐworkQueue¡¢×î´óÏß³ÌmaximumPoolSize£¬Èç¹ûÈýÕ߶¼ÂúÁË£¬Ê¹ÓÃhandler´¦Àí±»¾Ü¾øµÄÈÎÎñ¡£
µ±Ï̳߳ØÖеÄÏß³ÌÊýÁ¿´óÓÚ corePoolSizeʱ£¬Èç¹ûijÏ߳̿ÕÏÐʱ¼ä³¬¹ýkeepAliveTime£¬Ï߳̽«±»ÖÕÖ¹¡£ÕâÑù£¬Ï̳߳ؿÉÒÔ¶¯Ì¬µÄµ÷Õû³ØÖеÄÏß³ÌÊý¡£
unit¿ÉÑ¡µÄ²ÎÊýΪjava.util.concurrent.TimeUnitÖеļ¸¸ö¾²Ì¬ÊôÐÔ£º
NANOSECONDS¡¢MICROSECONDS¡¢MILLISECONDS¡¢SECONDS¡£
workQueueÎÒ³£ÓõÄÊÇ£ºjava.util.concurrent.ArrayBlockingQueue
handlerÓÐËĸöÑ¡Ôñ£º
ThreadPoolExecutor.AbortPolicy()
Å׳öjava.util.concurrent.RejectedExecutionExceptionÒì³£
ThreadPoolExecutor.CallerRunsPolicy()
ÖØÊÔÌí¼Óµ±Ç°µÄÈÎÎñ£¬Ëû»á×Ô¶¯Öظ´µ÷ÓÃexecute()·½·¨
ThreadPoolExecuto
Ïà¹ØÎĵµ£º
Inner classes, also called Nested Classes, are nothing but classes that are defined within other classes. The nesting is a relationship between classes, not objects.
Inner classes have clearly two benefits, name control & access control. In Java, this benefit is not as important because Java pa ......
AntÓ÷¨——Õª×Ô¡¶ÇáÁ¿¼¶Java EEÆóÒµÓ¦ÓÃʵս¡·
1.6 AntµÄ°²×°ºÍʹÓÃ
AntÊÇÒ»ÖÖ»ùÓÚJavaµÄÉú³É¹¤¾ß
¡£´Ó×÷ÓÃÉÏÀ´¿´£¬ËüÓÐЩÀàËÆÓÚC±à³Ì£¨Unixƽ̨ÉÏʹÓý϶ࣩÖеÄMake¹¤¾ß£¬C/C++ÏîÄ¿
¾³£Ê¹ÓÃMake¹¤¾ßÀ´¹ÜÀíÕû¸öÏîÄ¿µÄ±àÒë¡¢Éú³É¡£
MakeʹÓÃShellÃüÁîÀ´¶¨Òå
Éú³ÉÈÎÎñ£¬²¢¶¨ÒåÈÎÎñÖ®¼äµÄÒÀÀµ¹Øϵ£¬ÒÔ±ãË ......
import java.awt.*;
import java.awt.event.*;
public class TestFrame {
Frame fm = new Frame();
public void init(){
fm.setSize(300,300);
Button btn = new Button("ok");
fm.add(btn);
btn.addActionListener(ne ......
ÏÈ¿´¿´ÏÂÃæµÄ´úÂ룬´ó¼Ò²Â²ÂÊä³öÊÇʲô
package com.captain.test;
public class ArrayTest {
public static void main(String[] args){
//н¨Ò»¸ö¶ÔÏó£¨OneNum£©Êý×飨¸³ÖµÎª5¡¢3¡¢4£©
OneNum[] ac = {new OneNum(5),new OneNum(3),new OneNum(4)};
//н¨Ò»¸öÓëacͬ³¤¶ÈµÄ¶ÔÏó£¨OneNum£©Êý×é
OneNum[] n ......
ÇëÎʸ÷λ´ó룬Èç¹ûÓÃJAVAÀ´ÖÆ×÷¶¯Ì¬µÄ¸öÈËÍøÕ¾£¬¶¼ÐèÒªÄÄЩ·½ÃæµÄ֪ʶºÍ×¼±¸¹¤×÷£¿¿ª·¢¹¤¾ßʹÓÃʲô±È½ÏºÃ£¬Eclipse»¹ÊÇMyEclipse¡¢»¹ÊÇNetBeans£¿Çë¸ßÊÖÖ¸½Ì……
ÒÔÇ°ÓÃEclipse×ö¹ý¹«Ë¾µÄÍøÕ¾£¬Ê±¼ä¸ôµÄÓÐЩ̫¾ÃÁË¡¢¶¼Íü¼ÇÊÇÔõÑùÒ»¸ö¹ý³ÌÁË¡£JSP¡¢SERLET¡¢HIBERNATE¡ ......