use of org.forgerock.util.thread.listener.ShutdownManager 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;
}
Aggregations