use of org.apache.sling.commons.threads.ThreadPool in project sling by apache.
the class DefaultThreadPoolManager method get.
/**
* @see org.apache.sling.commons.threads.ThreadPoolManager#get(java.lang.String)
*/
public ThreadPool get(final String name) {
final String poolName = (name == null ? DEFAULT_THREADPOOL_NAME : name);
Entry entry = null;
boolean created = false;
ThreadPool threadPool = null;
synchronized (this.pools) {
entry = this.pools.get(poolName);
if (entry == null) {
this.logger.debug("Creating new pool with name {}", poolName);
final ModifiableThreadPoolConfig config = new ModifiableThreadPoolConfig();
entry = new Entry(null, config, poolName, bundleContext);
created = true;
this.pools.put(poolName, entry);
}
threadPool = entry.incUsage();
}
if (created) {
entry.registerMBean();
}
return threadPool;
}
use of org.apache.sling.commons.threads.ThreadPool in project sling by apache.
the class DefaultThreadPoolManager method create.
public ThreadPool create(ThreadPoolConfig config, String label) {
if (config == null) {
throw new IllegalArgumentException("Config must not be null.");
}
if (label == null) {
// generate the label by taking the first external frame off the stack trace
final StackTraceElement[] stackTrace = new Exception().getStackTrace();
if (stackTrace != null && stackTrace.length > 1) {
if (stackTrace[1].getClassName().equals(this.getClass().getName())) {
label = stackTrace[2].getClassName();
} else {
label = stackTrace[1].getClassName();
}
}
}
final String name = "ThreadPool-" + UUID.randomUUID().toString() + (label == null ? "" : " (" + label + ")");
final Entry entry = new Entry(null, config, name, bundleContext);
ThreadPool threadPool = null;
synchronized (this.pools) {
this.pools.put(name, entry);
threadPool = entry.incUsage();
}
entry.registerMBean();
return threadPool;
}
Aggregations