Search in sources :

Example 1 with ThreadPool

use of com.iplanet.am.util.ThreadPool in project OpenAM by OpenRock.

the class SessionPollerPool method initPollerPool.

/**
     * Configures the threadpool, and registers the threadpool with the shutdown manager so that it correctly
     * shuts down when the server is brought down.
     */
private synchronized void initPollerPool() {
    if (!pollerPoolInitialized) {
        if (pollingEnabled) {
            int poolSize = SystemProperties.getAsInt(Constants.POLLING_THREADPOOL_SIZE, DEFAULT_POOL_SIZE);
            int threshold = SystemProperties.getAsInt(Constants.POLLING_THREADPOOL_THRESHOLD, DEFAULT_THRESHOLD);
            final ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
            threadPool = new ThreadPool("amSessionPoller", poolSize, threshold, true, debug);
            shutdownMan.addShutdownListener(new ShutdownListener() {

                public void shutdown() {
                    threadPool.shutdown();
                    threadPool = null;
                    pollerPoolInitialized = false;
                }
            });
            pollerPoolInitialized = true;
        } else {
            if (debug.messageEnabled()) {
                debug.message("Session Cache cleanup is set to " + sessionCleanupEnabled);
            }
        }
    }
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) ThreadPool(com.iplanet.am.util.ThreadPool) ShutdownManager(org.forgerock.util.thread.listener.ShutdownManager)

Example 2 with ThreadPool

use of com.iplanet.am.util.ThreadPool in project OpenAM by OpenRock.

the class SMSThreadPool method initialize.

static synchronized void initialize(boolean reinit) {
    // Check if already initialized
    if (reinit) {
        initialized = false;
    }
    if (initialized) {
        return;
    }
    int newPoolSize = DEFAULT_POOL_SIZE;
    try {
        if (SystemProperties.isServerMode()) {
            newPoolSize = Integer.parseInt(SystemProperties.get(Constants.SM_THREADPOOL_SIZE));
        } else {
            // For clients and CLIs, it is hardcoded to 3
            newPoolSize = 2;
        }
    } catch (Exception e) {
        newPoolSize = DEFAULT_POOL_SIZE;
    }
    if (newPoolSize == poolSize) {
        // No change in the pool size, return
        return;
    } else {
        poolSize = newPoolSize;
    }
    if (debug.messageEnabled()) {
        debug.message("SMSThreadPool: poolSize=" + poolSize);
    }
    ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
    if (thrdPool != null) {
        // Create a new thread pool
        thrdPool = new ThreadPool("smIdmThreadPool", poolSize, DEFAULT_TRESHOLD, false, debug);
        // Create the shutdown hook
        ShutdownListener newShutdownListener = new ShutdownListener() {

            public void shutdown() {
                thrdPool.shutdown();
            }
        };
        // Register to shutdown hook
        shutdownMan.replaceShutdownListener(shutdownListener, newShutdownListener, null);
    } else {
        // Create a new thread pool
        thrdPool = new ThreadPool("smIdmThreadPool", poolSize, DEFAULT_TRESHOLD, false, debug);
        // Create the shutdown hook
        shutdownListener = new ShutdownListener() {

            public void shutdown() {
                thrdPool.shutdown();
            }
        };
        // Register to shutdown hook
        shutdownMan.addShutdownListener(shutdownListener);
    }
    initialized = true;
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) ThreadPool(com.iplanet.am.util.ThreadPool) ShutdownManager(org.forgerock.util.thread.listener.ShutdownManager) ThreadPoolException(com.iplanet.am.util.ThreadPoolException)

Aggregations

ThreadPool (com.iplanet.am.util.ThreadPool)2 ShutdownListener (org.forgerock.util.thread.listener.ShutdownListener)2 ShutdownManager (org.forgerock.util.thread.listener.ShutdownManager)2 ThreadPoolException (com.iplanet.am.util.ThreadPoolException)1