亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? threadpool.java

?? 一個java方面的消息訂閱發送的源碼
?? JAVA
字號:
/**
 * Redistribution and use of this software and associated documentation
 * ("Software"), with or without modification, are permitted provided
 * that the following conditions are met:
 *
 * 1. Redistributions of source code must retain copyright
 *    statements and notices.  Redistributions must also contain a
 *    copy of this document.
 *
 * 2. Redistributions in binary form must reproduce the
 *    above copyright notice, this list of conditions and the
 *    following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. The name "Exolab" must not be used to endorse or promote
 *    products derived from this Software without prior written
 *    permission of Exoffice Technologies.  For written permission,
 *    please contact info@exolab.org.
 *
 * 4. Products derived from this Software may not be called "Exolab"
 *    nor may "Exolab" appear in their names without prior written
 *    permission of Exoffice Technologies. Exolab is a registered
 *    trademark of Exoffice Technologies.
 *
 * 5. Due credit should be given to the Exolab Project
 *    (http://www.exolab.org/).
 *
 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Copyright 2000-2004 (C) Exoffice Technologies Inc. All Rights Reserved.
 *
 * $Id: ThreadPool.java,v 1.1 2004/11/26 01:50:35 tanderson Exp $
 */
package org.exolab.jms.common.threads;

import org.exolab.jms.common.util.FifoQueue;


/**
 * Thread manager that maintains a list of worker threads and allocates
 * them to execute objects asynchronously. This enables execution without the
 * overhead of thread creation.
 * <p>
 * The thread pool is constructed with a fixed number of threads.
 * The number of threads cannot be increased after the pool is created, but
 * there can be multiple thread pools.
 * <p>
 * There are two methods to execute threads:
 * <ul>
 *   <li>{@link #execute} - this executes an {@link Runnable} object using
 *       the first available worker thread. If no threads are available,
 *       the call blocks until one is free.</li>
 *   <li>{@link #queue} - this queues an {@link Runnable} object for later
 *       execution by the first available worker thread. It returns immediately
 *       without blocking.</li>
 * </ul>
 *
 * @version     $Revision: 1.1 $ $Date: 2004/11/26 01:50:35 $
 * @author      <a href="mailto:mourikis@exolab.org">Jim Mourikis</a>
 * @see         CompletionListener
 */
public class ThreadPool {

    /**
     * The name of this thread pool
     */
    private final String _name;

    /**
     * The thread group of this pool
     */
    private ThreadGroup _group;

    /**
     * The list of idle threads ready for use
     */
    private FifoQueue _idleWorkers;

    /**
     * The list of all worker threads, working or idle
     */
    private ThreadPoolWorker[] _workers;

    /**
     * The queue of pending {@link Runnable} instances
     */
    private QueueWorker _queue;

    /**
     * Seed value for creating unique thread pool names
     */
    private static volatile int _poolSeed = 0;


    /**
     * Create a new thread pool with the requested number of threads.
     * Each thread will be allocated to a new ThreadGroup named
     * 'ThreadPool-'<id> where id is a number incremented for each new thread
     * pool.
     *
     * @param threads the number of threads to allocate to the pool
     * @throws IllegalArgumentException if the number of threads is less than 1
     */
    public ThreadPool(int threads) {
        this(threads, false);
    }

    /**
     * Create a new thread pool with the requested number of threads.
     * Each thread will be allocated to a new ThreadGroup named
     * 'ThreadPool-'<id> where id is a number incremented for each new thread
     * pool.
     *
     * @param threads the number of threads to allocate to the pool
     * @param daemon if <code>true</code> all threads will be daemon threads
     * @throws IllegalArgumentException if the number of threads is less than 1
     */
    public ThreadPool(int threads, boolean daemon) {
        this("ThreadPool-" +  ++_poolSeed, threads, daemon);
    }

    /**
     * Create a new thread pool with the requested number of threads.
     * Each thread will be allocated to a new ThreadGroup with the specified
     * name.
     *
     * @param name the name of the thread group
     * @param threads the number of threads to allocate to the pool
     * @throws IllegalArgumentException if the number of threads is less than 1
     */
    public ThreadPool(String name, int threads) {
        this(name, threads, false);
    }

    /**
     * Create a new thread pool with the requested number of threads.
     * Each thread will be allocated to a new ThreadGroup with the specified
     * name.
     *
     * @param name the name of the thread group
     * @param threads the number of threads to allocate to the pool
     * @param daemon if <code>true</code> all threads will be daemon threads
     * @throws IllegalArgumentException if the number of threads is less than 1
     */
    public ThreadPool(String name, int threads, boolean daemon) {
        this(new ThreadGroup(name), threads, daemon);
    }

    /**
     * Create a new thread pool with the requested number of threads.
     * Each thread will be associated with the supplied thread group.
     *
     * @param group the thread group
     * @param threads the number of threads to allocate to the pool
     * @param daemon if <code>true</code> all threads will be daemon threads
     * @throws IllegalArgumentException if the number of threads is less than 1
     */
    public ThreadPool(ThreadGroup group, int threads, boolean daemon) {
        _name = group.getName();
        _group = new ThreadGroup(_name);
        if (daemon) {
            _group.setDaemon(true);
        }
        if (threads < 1) {
            throw new IllegalArgumentException(
                "Argument 'threads' must be > 0");
        }

        _idleWorkers = new FifoQueue(threads);
        _workers = new ThreadPoolWorker[threads];

        for (int i = 0; i < _workers.length; ++i) {
            String id = _name + "-Worker-" + i;
            _workers[i] = new ThreadPoolWorker(_group, id, _idleWorkers);
        }
    }

    /**
     * Execute the {@link Runnable} object using the next available
     * worker thread. This method will block until a worker thread is
     * available for use - once a worker thread becomes available it
     * will return immediately.
     *
     * @param target the work to perform
     * @throws InterruptedException if this thread is interrupted externally
     */
    public void execute(Runnable target) throws InterruptedException {
        // block (forever) until a worker is available
        ThreadPoolWorker worker = (ThreadPoolWorker) _idleWorkers.get();
        worker.process(target);
    }

    /**
     * Queue the {@link Runnable} object for execution using the next
     * available worker thread.<br/>
     * Unlike {@link #execute}, this method does not block.
     *
     * @param target the work to perform
     */
    public void queue(Runnable target) {
        queue(target, null);
    }

    /**
     * Queue the {@link Runnable} object for execution using the next
     * available worker thread. When the object completes execution, the
     * completion listener will be notified.<br/>
     * Unlike {@link #execute}, this method does not block.
     *
     * @param target the work to perform
     * @param listener the listener to notify when the object has completed
     * executing
     */
    public synchronized void queue(Runnable target,
                                   CompletionListener listener) {
        if (_queue == null) {
            _queue = new QueueWorker(this, _group, _name + "-QueueWorker");
        }
        _queue.add(target, listener);
    }

    /**
     * Shuts down and removes any idle threads from the queue.
     * Working threads will not be shutdown.
     * As working threads finish, and are added back to the idle queue
     * this call needs to be made again to shut them down and remove them.
     */
    public void stopRequestIdleWorkers() {
        try {
            Object[] idle = _idleWorkers.getAll();
            for (int i = 0; i < idle.length; i++) {
                ((ThreadPoolWorker) idle[i]).stopRequest();
            }
        } catch (InterruptedException exception) {
            // re-assert
            Thread.currentThread().interrupt();
        }
    }

    /**
     * Shuts down and removes all threads.
     * First all idle threads are removed and shutdown,
     * then all remaining work threads, are shutdown.
     */
    public void stopRequestAllWorkers() {
        final long delay = 250;
        stopRequestIdleWorkers();

        // give the idle workers a quick chance to die
        try {
            Thread.sleep(delay);
        } catch (InterruptedException ignore) {
        }

        for (int i = 0; i < _workers.length; i++) {
            if (_workers[i].isAlive()) {
                _workers[i].stopRequest();
            }
        }

        if (_queue != null && _queue.isAlive()) {
            _queue.stop();
        }
    }

    /**
     * Determines if there is at least one idle thread.
     * This never blocks.
     *
     * @return <code>true</code> if there are one or more idle threads
     */
    boolean hasIdleThread() {
        return (_idleWorkers.isEmpty() ? false : true);
    }

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久久亚洲蜜桃| 日韩在线播放一区二区| 亚洲大片一区二区三区| 国产成人av一区二区| 欧美一区二区网站| 一区二区三区在线视频播放| 国产一区二区三区免费播放 | 成人性生交大片免费| 欧美日韩二区三区| 中文字幕一区日韩精品欧美| 麻豆91精品91久久久的内涵| 欧美性猛交一区二区三区精品| 国产精品久久久久久久久快鸭| 久久99精品国产麻豆不卡| 欧美高清www午色夜在线视频| 成人免费在线视频观看| 国产精品69久久久久水密桃| 日韩美女一区二区三区| 日韩专区中文字幕一区二区| 欧美这里有精品| 一区二区不卡在线视频 午夜欧美不卡在 | 精久久久久久久久久久| 欧美在线999| 亚洲一区二区三区小说| 欧美性色综合网| 亚洲国产aⅴ天堂久久| 91麻豆福利精品推荐| 亚洲四区在线观看| 91免费视频网| 亚洲国产精品久久久久秋霞影院| 91成人免费在线视频| 一区二区三区中文字幕在线观看| 99久久99久久综合| 亚洲色图.com| 在线观看视频91| 亚洲综合在线观看视频| 欧美日韩免费高清一区色橹橹 | 国产自产高清不卡| 久久亚洲综合色一区二区三区| 久久成人免费日本黄色| 精品国产乱码久久久久久图片| 免费久久精品视频| 久久精品在线免费观看| 成人高清免费观看| 综合自拍亚洲综合图不卡区| 91黄色小视频| 亚洲va在线va天堂| 日韩精品中文字幕在线不卡尤物| 毛片av中文字幕一区二区| 久久天天做天天爱综合色| 丰满白嫩尤物一区二区| 一区二区三区四区av| 欧美久久久久久蜜桃| 精品一区二区三区不卡| 国产女主播一区| 欧美图区在线视频| 美女视频黄免费的久久| 国产欧美日韩另类一区| 在线视频一区二区免费| 美国三级日本三级久久99| 中文字幕va一区二区三区| 91亚洲精品久久久蜜桃网站| 婷婷开心久久网| 久久精品一区四区| 欧美特级限制片免费在线观看| 日韩av一区二区三区| 国产免费成人在线视频| 欧美在线一区二区| 国产高清无密码一区二区三区| 综合欧美亚洲日本| 日韩欧美久久久| 一本到高清视频免费精品| 精品一二线国产| 一区二区三区日韩精品视频| 久久久久久影视| 欧美无人高清视频在线观看| 国产激情一区二区三区| 午夜精品久久久久久久久久| 久久久精品综合| 精品视频999| 99久久久久免费精品国产| 久久不见久久见免费视频7| 亚洲精品视频在线| 国产片一区二区三区| 日韩一区二区三区高清免费看看| 97久久精品人人做人人爽50路| 精品一区二区三区影院在线午夜 | 欧美视频中文字幕| 高清shemale亚洲人妖| 免费成人美女在线观看| 亚洲自拍与偷拍| 亚洲欧美日韩电影| 国产精品天干天干在线综合| 337p亚洲精品色噜噜噜| 91官网在线免费观看| gogo大胆日本视频一区| 国产精品亚洲第一区在线暖暖韩国| 天涯成人国产亚洲精品一区av| 国产精品亲子伦对白| 2017欧美狠狠色| 精品乱人伦小说| 欧美一区三区四区| 欧美精品丝袜久久久中文字幕| 色综合久久综合网欧美综合网 | 亚洲丝袜另类动漫二区| 国产免费成人在线视频| 久久精品视频在线看| 日韩免费观看2025年上映的电影| 在线观看欧美日本| 在线欧美一区二区| 欧美性猛交xxxxxxxx| 在线国产电影不卡| 一本大道av伊人久久综合| 91在线无精精品入口| 99国产欧美久久久精品| 97se亚洲国产综合自在线| 99精品欧美一区| 91高清视频免费看| 欧美区视频在线观看| 91精品国产欧美日韩| 精品毛片乱码1区2区3区| 久久夜色精品一区| 日本一区二区三区久久久久久久久不 | 亚洲人成精品久久久久| 亚洲伦理在线免费看| 亚洲自拍都市欧美小说| 天天色综合成人网| 麻豆国产一区二区| 国产精品亚洲专一区二区三区| 成人免费毛片片v| 97久久精品人人爽人人爽蜜臀| 日本高清无吗v一区| 欧美日韩高清一区| 精品国产乱码久久久久久久| 欧美韩国日本一区| 亚洲美女视频在线| 三级影片在线观看欧美日韩一区二区| 日韩高清不卡在线| 国产·精品毛片| 在线观看免费一区| 欧美成人官网二区| 欧美国产日韩精品免费观看| 一区二区三区国产豹纹内裤在线| 日韩电影在线看| 粉嫩aⅴ一区二区三区四区五区| 色综合一区二区| 欧美一区二区高清| 日韩毛片精品高清免费| 五月天激情综合| 成人av资源下载| 欧美一区二区视频网站| 国产精品免费免费| 日本va欧美va瓶| 成人免费不卡视频| 日韩西西人体444www| 国产精品网站在线观看| 日韩成人午夜精品| a4yy欧美一区二区三区| 91精品国产欧美一区二区18| 中文字幕亚洲不卡| 麻豆成人综合网| 91黄色激情网站| 国产亚洲精品中文字幕| 日韩和的一区二区| 99精品视频中文字幕| 精品日韩一区二区| 亚洲小说春色综合另类电影| 顶级嫩模精品视频在线看| 欧美肥大bbwbbw高潮| 亚洲欧美激情视频在线观看一区二区三区| 奇米色一区二区三区四区| 激情久久五月天| 国产精品99久久久久久久vr| 欧美视频一区二区三区四区| 国产三级三级三级精品8ⅰ区| 性欧美大战久久久久久久久| 成人免费观看av| ww亚洲ww在线观看国产| 日本久久电影网| 欧美理论电影在线| 2023国产精品自拍| 奇米四色…亚洲| 欧美日韩精品一区二区三区| 亚洲欧洲国产日韩| 成人国产精品免费网站| 国产日韩视频一区二区三区| 免费成人深夜小野草| 91精品国产综合久久精品图片| 亚洲第一精品在线| 在线观看免费亚洲| 一区二区三区日韩在线观看| 91小宝寻花一区二区三区| 中文字幕一区在线观看| 不卡电影一区二区三区| 国产精品久久久久精k8| 国产精品亚洲专一区二区三区| 2020国产精品| 国产麻豆91精品| 欧美精彩视频一区二区三区| 高清视频一区二区|