本文整理汇总了Java中java.util.concurrent.ThreadPoolExecutor.getActiveCount方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadPoolExecutor.getActiveCount方法的具体用法?Java ThreadPoolExecutor.getActiveCount怎么用?Java ThreadPoolExecutor.getActiveCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ThreadPoolExecutor
的用法示例。
在下文中一共展示了ThreadPoolExecutor.getActiveCount方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: check
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public Status check() {
DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
Map<String, Object> executors = dataStore.get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY);
StringBuilder msg = new StringBuilder();
Status.Level level = Status.Level.OK;
for(Map.Entry<String, Object> entry : executors.entrySet()) {
String port = entry.getKey();
ExecutorService executor = (ExecutorService) entry.getValue();
if (executor != null && executor instanceof ThreadPoolExecutor) {
ThreadPoolExecutor tp = (ThreadPoolExecutor) executor;
boolean ok = tp.getActiveCount() < tp.getMaximumPoolSize() - 1;
Status.Level lvl = Status.Level.OK;
if(!ok) {
level = Status.Level.WARN;
lvl = Status.Level.WARN;
}
if(msg.length() > 0) {
msg.append(";");
}
msg.append("Pool status:" + lvl
+ ", max:" + tp.getMaximumPoolSize()
+ ", core:" + tp.getCorePoolSize()
+ ", largest:" + tp.getLargestPoolSize()
+ ", active:" + tp.getActiveCount()
+ ", task:" + tp.getTaskCount()
+ ", service port: " + port);
}
}
return msg.length() == 0 ? new Status(Status.Level.UNKNOWN) : new Status(level, msg.toString());
}
示例2: getThreadActiveSize
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public int getThreadActiveSize() {
if (executorService instanceof ThreadPoolExecutor) {
ThreadPoolExecutor pool = (ThreadPoolExecutor) executorService;
return pool.getActiveCount();
}
return 0;
}
示例3: awaitIdleness
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
static void awaitIdleness(ThreadPoolExecutor tpe, long taskCount) {
restart: for (;;) {
// check twice to make chance of race vanishingly small
for (int i = 0; i < 2; i++) {
if (tpe.getQueue().size() != 0 ||
tpe.getActiveCount() != 0 ||
tpe.getCompletedTaskCount() != taskCount) {
Thread.yield();
continue restart;
}
}
return;
}
}
示例4: process
import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
* Adds the distribution manager that is started up to the current DM's list of members.
*
* This method is invoked on the receiver side
*/
@Override
protected void process(DistributionManager dm) {
switch (this.op) {
case DRAIN_POOL:
Assert.assertTrue(this.id != null);
// wait 10 seconds for the high priority queue to drain
long endTime = System.currentTimeMillis() + 10000;
ThreadPoolExecutor pool = (ThreadPoolExecutor) dm.getHighPriorityThreadPool();
while (pool.getActiveCount() > 1 && System.currentTimeMillis() < endTime) {
boolean interrupted = Thread.interrupted();
try {
Thread.sleep(500);
} catch (InterruptedException ie) {
interrupted = true;
dm.getCancelCriterion().checkCancelInProgress(ie);
// if interrupted, we must be shutting down
return;
} finally {
if (interrupted)
Thread.currentThread().interrupt();
}
}
if (pool.getActiveCount() > 1) {
logger.warn(LocalizedMessage.create(
LocalizedStrings.HighPriorityAckedMessage_0_THERE_ARE_STILL_1_OTHER_THREADS_ACTIVE_IN_THE_HIGH_PRIORITY_THREAD_POOL,
new Object[] {this, Integer.valueOf(pool.getActiveCount() - 1)}));
}
ReplyMessage.send(getSender(), processorId, null, dm);
break;
case DUMP_STACK:
if (this.processorId > 0) {
try {
byte[] zippedStacks = OSProcess.zipStacks();
ReplyMessage.send(getSender(), processorId, zippedStacks, dm);
} catch (IOException e) {
ReplyMessage.send(getSender(), processorId, new ReplyException(e), dm);
}
} else {
OSProcess.printStacks(0, this.useNative);
}
}
}