{"rsdb":{"rid":"397620","subhead":"","postdate":"0","aid":"273661","fid":"76","uid":"1","topic":"1","content":"
\n

\u4e0a\u7bc7\u6587\u7ae012\u5206\u949f\u4eceExecutor\u81ea\u9876\u5411\u4e0b\u5f7b\u5e95\u641e\u61c2\u7ebf\u7a0b\u6c60<\/a>\u4e2d\u6211\u4eec\u804a\u5230\u7ebf\u7a0b\u6c60\uff0c\u800c\u7ebf\u7a0b\u6c60\u4e2d\u5305\u542b\u963b\u585e\u961f\u5217<\/p> \n

\u8fd9\u7bc7\u6587\u7ae0\u6211\u4eec\u4e3b\u8981\u804a\u804a\u5e76\u53d1\u5305\u4e0b\u7684\u963b\u585e\u961f\u5217<\/p> \n

\u963b\u585e\u961f\u5217<\/h4> \n

\u4ec0\u4e48\u662f\u961f\u5217\uff1f<\/p> \n

\u961f\u5217\u7684\u5b9e\u73b0\u53ef\u4ee5\u662f\u6570\u7ec4\u3001\u4e5f\u53ef\u4ee5\u662f\u94fe\u8868\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5148\u8fdb\u5148\u51fa\u7684\u987a\u5e8f\u961f\u5217\uff0c\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u5148\u8fdb\u540e\u51fa\u7684\u6808\u961f\u5217<\/p> \n

\u90a3\u4ec0\u4e48\u662f\u963b\u585e\u961f\u5217\uff1f<\/p> \n

\u5728\u7ecf\u5178\u7684\u751f\u4ea7\u8005\/\u6d88\u8d39\u8005\u6a21\u578b\u4e2d\uff0c\u751f\u4ea7\u8005\u4eec\u5c06\u751f\u4ea7\u7684\u5143\u7d20\u653e\u5165\u961f\u5217\uff0c\u800c\u6d88\u8d39\u8005\u4eec\u4ece\u961f\u5217\u83b7\u53d6\u5143\u7d20\u6d88\u8d39<\/p> \n

\u5f53\u961f\u5217\u5df2\u6ee1\uff0c\u6211\u4eec\u4f1a\u624b\u52a8\u963b\u585e\u751f\u4ea7\u8005\uff0c\u76f4\u5230\u6d88\u8d39\u8005\u6d88\u8d39\u518d\u6765\u624b\u52a8\u5524\u9192\u751f\u4ea7\u8005<\/p> \n

\u5f53\u961f\u5217\u4e3a\u7a7a\uff0c\u6211\u4eec\u4f1a\u624b\u52a8\u963b\u585e\u6d88\u8d39\u8005\uff0c\u76f4\u5230\u751f\u4ea7\u8005\u751f\u4ea7\u518d\u6765\u624b\u52a8\u5524\u9192\u6d88\u8d39\u8005<\/p> \n

\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\u7531\u4e8e\u4f7f\u7528\u7684\u662f\u666e\u901a\u961f\u5217\uff0c\u963b\u585e\u4e0e\u5524\u9192\u6211\u4eec\u9700\u8981\u624b\u52a8\u64cd\u4f5c\uff0c\u4fdd\u8bc1\u540c\u6b65\u673a\u5236<\/p> \n

\u963b\u585e\u961f\u5217\u5728\u961f\u5217\u7684\u57fa\u7840\u4e0a\u63d0\u4f9b\u7b49\u5f85\/\u901a\u77e5\u529f\u80fd\uff0c\u7528\u4e8e\u7ebf\u7a0b\u95f4\u7684\u901a\u4fe1\uff0c\u907f\u514d\u7ebf\u7a0b\u7ade\u4e89\u6b7b\u9501<\/strong><\/p> \n

\u751f\u4ea7\u8005\u53ef\u4ee5\u770b\u6210\u5f80\u7ebf\u7a0b\u6c60\u6dfb\u52a0\u4efb\u52a1\u7684\u7528\u6237\u7ebf\u7a0b\uff0c\u800c\u6d88\u8d39\u8005\u5219\u662f\u7ebf\u7a0b\u6c60\u4e2d\u7684\u5de5\u4f5c\u7ebf\u7a0b<\/p> \n

\u5f53\u963b\u585e\u961f\u5217\u4e3a\u7a7a\u65f6\u963b\u585e\u5de5\u4f5c\u7ebf\u7a0b\u83b7\u53d6\u4efb\u52a1\uff0c\u5f53\u963b\u585e\u961f\u5217\u5df2\u6ee1\u65f6\u963b\u585e\u7528\u6237\u7ebf\u7a0b\u5411\u961f\u5217\u4e2d\u6dfb\u52a0\u4efb\u52a1\uff08\u521b\u5efa\u975e\u6838\u5fc3\u7ebf\u7a0b\u3001\u62d2\u7edd\u7b56\u7565\uff09<\/p> \n

API<\/h5> \n

\u963b\u585e\u961f\u5217\u63d0\u4f9b\u4e00\u4e0b\u56db\u79cd\u6dfb\u52a0\u3001\u5220\u9664\u5143\u7d20\u7684API\uff0c\u6211\u4eec\u5e38\u7528\u963b\u585e\u7b49\u5f85\/\u8d85\u65f6\u963b\u585e\u7b49\u5f85\u7684API<\/p> \n \n \n \n \n \n \n
\u65b9\u6cd5\u540d<\/th> \n \u629b\u51fa\u5f02\u5e38<\/th> \n \u8fd4\u56detrue\/false<\/th> \n \u963b\u585e\u7b49\u5f85<\/th> \n \u8d85\u65f6\u963b\u585e\u7b49\u5f85<\/th> \n <\/tr> \n <\/thead> \n
\u6dfb\u52a0<\/td> \n add(Object)<\/td> \n offer(Object)<\/td> \n put(Object)<\/td> \n offer(Object,long,TimeUnit)<\/td> \n <\/tr> \n
\u5220\u9664<\/td> \n remove()<\/td> \n poll()<\/td> \n take()<\/td> \n poll(long,TimeUnit)<\/td> \n <\/tr> \n <\/tbody> \n <\/table> \n
    \n
  1. \u629b\u51fa\u5f02\u5e38:\u961f\u6ee1add \u629b\u51fa\u5f02\u5e38IllegalStateExceptio<\/code> \uff1b\u961f\u7a7aremove \u629b\u51fa\u5f02\u5e38NoSuchElementException<\/code><\/li> \n
  2. \u8fd4\u56de\u503c: \u961f\u6ee1offer\u8fd4\u56defalse\uff0c\u961f\u7a7apoll\u8fd4\u56denull<\/li> \n
  3. \u963b\u585e\u7b49\u5f85: \u961f\u6ee1\u65f6put\u4f1a\u963b\u585e\u7ebf\u7a0b \u6216 \u961f\u7a7a\u65f6take\u4f1a\u963b\u585e\u7ebf\u7a0b<\/li> \n
  4. \u8d85\u65f6\u963b\u585e\u7b49\u5f85: \u5728\u963b\u585e\u7b49\u5f85\u3001\u8fd4\u56detrue\/false\u7684\u57fa\u7840\u4e0a\u589e\u52a0\u8d85\u65f6\u7b49\u5f85\uff08\u7b49\u5f85\u4e00\u5b9a\u65f6\u95f4\u5c31\u9000\u51fa\u7b49\u5f85\uff09<\/li> \n <\/ol> \n
    \u963b\u585e\u961f\u5217\u7684\u516c\u5e73\u4e0e\u4e0d\u516c\u5e73<\/h5> \n

    \u4ec0\u4e48\u662f\u963b\u585e\u961f\u5217\u7684\u516c\u5e73\u4e0e\u4e0d\u516c\u5e73\uff1f<\/p> \n

    \u5f53\u963b\u585e\u961f\u5217\u5df2\u6ee1\u65f6\uff0c\u5982\u679c\u662f\u516c\u5e73\u7684\uff0c\u90a3\u4e48\u963b\u585e\u7684\u7ebf\u7a0b\u6839\u636e\u5148\u540e\u987a\u5e8f\u4ece\u963b\u585e\u961f\u5217\u4e2d\u83b7\u53d6\u5143\u7d20\uff0c\u4e0d\u516c\u5e73\u5219\u53cd\u4e4b<\/p> \n

    \u5b9e\u9645\u4e0a\u963b\u585e\u961f\u5217\u7684\u516c\u5e73\u4e0e\u4e0d\u516c\u5e73\uff0c\u8981\u770b\u5b9e\u73b0\u963b\u585e\u961f\u5217\u7684\u9501\u662f\u5426\u516c\u5e73<\/p> \n

    \u963b\u585e\u961f\u5217\u4e00\u822c\u9ed8\u8ba4\u4f7f\u7528\u4e0d\u516c\u5e73\u9501<\/p> \n

    ArrayBlockingQueue<\/h4> \n

    \u4ece\u540d\u79f0\u770b\u5c31\u53ef\u4ee5\u77e5\u9053\u5b83\u662f\u6570\u7ec4\u5b9e\u73b0\u7684\uff0c\u6211\u4eec\u5148\u6765\u770b\u770b\u5b83\u6709\u54ea\u4e9b\u91cd\u8981\u5b57\u6bb5<\/p> \n

     public class ArrayBlockingQueue<E> extends AbstractQueue<E>\n         implements BlockingQueue<E>, java<\/a>.io.Serializable {\n ?\n     \/\/\u5b58\u50a8\u5143\u7d20\u7684\u6570\u7ec4\n     final Object[] items;\n ?\n     \/\/\u8bb0\u5f55\u5143\u7d20\u51fa\u961f\u7684\u4e0b\u6807\n     int takeIndex;\n ?\n     \/\/\u8bb0\u5f55\u5143\u7d20\u5165\u961f\u7684\u4e0b\u6807\n     int putIndex;\n ?\n     \/\/\u961f\u5217\u4e2d\u5143\u7d20\u6570\u91cf\n     int count\uff1b\n ?\n     \/\/\u4f7f\u7528\u7684\u9501\n     final ReentrantLock lock;\n ?\n     \/\/\u51fa\u961f\u7684\u7b49\u5f85\u961f\u5217\uff0c\u4f5c\u7528\u4e8e\u6d88\u8d39\u8005\n     private final Condition notEmpty;\n ?\n     \/\/\u5165\u961f\u7684\u7b49\u5f85\u961f\u5217\uff0c\u4f5c\u7528\u4e8e\u751f\u4ea7\u8005\n     private final Condition notFull;\n     \n }\n<\/code><\/pre> \n 

    \u770b\u5b8c\u5173\u952e\u5b57\u6bb5\uff0c\u6211\u4eec\u53ef\u4ee5\u77e5\u9053\uff1aArrayBlockingQueue<\/code>\u7531\u6570\u7ec4\u5b9e\u73b0\u3001\u4f7f\u7528\u5e76\u53d1\u5305\u4e0b\u7684\u53ef\u91cd\u5165\u9501\u3001\u540c\u65f6\u7528\u4e24\u4e2a\u7b49\u5f85\u961f\u5217\u4f5c\u7528\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005<\/p> \n

    \u4e3a\u4ec0\u4e48\u51fa\u961f\u3001\u5165\u961f\u8981\u4f7f\u7528\u4e24\u4e2a\u4e0b\u6807\u8bb0\u5f55\uff1f<\/p> \n

    \u5b9e\u9645\u4e0a\u5b83\u662f\u4e00\u4e2a\u73af\u5f62\u6570\u7ec4\uff0c\u5728\u521d\u59cb\u5316\u540e\u5c31\u4e0d\u6539\u53d8\u5927\u5c0f\uff0c\u540e\u7eed\u67e5\u770b\u6e90\u7801\u81ea\u7136\u80fd\u660e\u767d\u5b83\u662f\u73af\u5f62\u6570\u7ec4<\/p> \n

    \u5728\u6784\u9020\u5668\u4e2d\u3001\u521d\u59cb\u5316\u6570\u7ec4\u5bb9\u91cf\uff0c\u540c\u65f6\u4f7f\u7528\u975e\u516c\u5e73\u9501<\/p> \n

         public ArrayBlockingQueue(int capacity) {\n         this(capacity, false);\n     }\n ?\n     public ArrayBlockingQueue(int capacity, boolean fair) {\n         if (capacity <= 0)\n             throw new IllegalArgumentException();\n         this.items = new Object[capacity];\n         \/\/\u9501\u662f\u5426\u4e3a\u516c\u5e73\u9501\n         lock = new ReentrantLock(fair);\n         notEmpty = lock.newCondition();\n         notFull =  lock.newCondition();\n     }\n<\/code><\/pre> \n 

    ArrayBlockingQueue\u7684\u516c\u5e73\u6027\u662f\u7531ReentrantLock\u6765\u5b9e\u73b0\u7684<\/p> \n

    \u6211\u4eec\u6765\u770b\u770b\u5165\u961f\u65b9\u6cd5\uff0c\u5165\u961f\u65b9\u6cd5\u90fd\u5927\u540c\u5c0f\u5f02\uff0c\u6211\u4eec\u672c\u6587\u90fd\u67e5\u770b\u652f\u6301\u8d85\u65f6\u3001\u54cd\u5e94\u4e2d\u65ad\u7684\u65b9\u6cd5<\/p> \n

         public boolean offer(E e, long timeout, TimeUnit unit)\n         throws InterruptedException {\n         \/\/\u68c0\u67e5\u7a7a\u6307\u9488\n         checkNotNull(e);\n         \/\/\u83b7\u53d6\u8d85\u65f6\u7eb3\u79d2\n         long nanos = unit.toNanos(timeout);\n         final ReentrantLock lock = this.lock;\n         \/\/\u52a0\u9501\n         lock.lockInterruptibly();\n    &nb","orderid":"0","title":"10\u5206\u949f\u4ece\u5b9e\u73b0\u548c\u4f7f\u7528\u573a\u666f\u804a\u804a\u5e76\u53d1\u5305\u4e0b\u7684\u963b\u585e\u961f\u5217(\u4e00)","smalltitle":"","mid":"0","fname":"JAVA","special_id":"0","bak_id":"0","info":"0","hits":"367","pages":"7","comments":"0","posttime":"2023-09-23 15:44:47","list":"1695455087","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"10\u5206<\/A> \u949f\u4ece\u5b9e<\/A> \u5305\u4e0b\u7684<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"112.94.1.100","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"10\u5206\u949f\u4ece\u5b9e\u73b0\u548c\u4f7f\u7528\u573a\u666f\u804a\u804a\u5e76\u53d1\u5305\u4e0b\u7684\u963b\u585e\u961f\u5217","lastview":"1713309925","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}