本文整理汇总了Java中java.lang.Thread.State.RUNNABLE属性的典型用法代码示例。如果您正苦于以下问题:Java State.RUNNABLE属性的具体用法?Java State.RUNNABLE怎么用?Java State.RUNNABLE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.lang.Thread.State
的用法示例。
在下文中一共展示了State.RUNNABLE属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toThreadState
/** taken from sun.misc.VM
*
* Returns Thread.State for the given threadStatus
*/
private static Thread.State toThreadState(int threadStatus) {
if ((threadStatus & JVMTI_THREAD_STATE_RUNNABLE) != 0) {
return State.RUNNABLE;
} else if ((threadStatus & JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER) != 0) {
return State.BLOCKED;
} else if ((threadStatus & JVMTI_THREAD_STATE_WAITING_INDEFINITELY) != 0) {
return State.WAITING;
} else if ((threadStatus & JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT) != 0) {
return State.TIMED_WAITING;
} else if ((threadStatus & JVMTI_THREAD_STATE_TERMINATED) != 0) {
return State.TERMINATED;
} else if ((threadStatus & JVMTI_THREAD_STATE_ALIVE) == 0) {
return State.NEW;
} else {
return State.RUNNABLE;
}
}
示例2: isSaturated
protected boolean isSaturated() {
if (getPoolSize() <= 3) {
return DEBUG;
}
int corePoolSize = getCorePoolSize();
int i = CountedTask.mNumRunning.get();
int size = mThreads.size();
if (i < corePoolSize || i < size) {
return true;
}
boolean z;
synchronized (mThreads) {
Iterator<Thread> it = mThreads.iterator();
size = 0;
while (it.hasNext()) {
State state = it.next().getState();
if (state == State.RUNNABLE || state == State.NEW) {
i = size + 1;
} else {
if (state == State.TERMINATED) {
it.remove();
}
i = size;
}
size = i;
}
}
z = size >= corePoolSize;
return z;
}
示例3: run
@Override
public void run() {
//According to this post the thread is still in Runnable although it's waiting for
//file/http resources
//https://stackoverflow.com/questions/20795295/why-jstack-out-says-thread-state-is-runnable-while-socketread
if (mainThread.getState() == State.RUNNABLE) {
//Based on this post we have to check the top element of the stack
//https://stackoverflow.com/questions/20891386/how-to-detect-thread-being-blocked-by-io
StackTraceElement[] stackTrace = mainThread.getStackTrace();
StackTraceElement topElement = stackTrace[stackTrace.length - 1];
if (topElement.isNativeMethod()) {
//Socket/SQL (connect) - java.net.DualStackPlainSocketImpl.connect0
//Socket/SQL (read) - java.net.SocketInputStream.socketRead0
//Socket/SQL (write) - java.net.SocketOutputStream.socketWrite0
if (isElementEqual(topElement, "java.net.DualStackPlainSocketImpl", "connect0")
|| isElementEqual(topElement, "java.net.SocketInputStream", "socketRead0")
|| isElementEqual(topElement, "java.net.SocketOutputStream", "socketWrite0")) {
plugin.getBlockActionManager().logCurrentStack("Server is performing {1} on the main thread. "
+ "Properly caused by {0}", "java.net.SocketStream");
} //File (in) - java.io.FileInputStream.readBytes
//File (out) - java.io.FileOutputStream.writeBytes
else if (isElementEqual(topElement, "java.io.FileInputStream", "readBytes")
|| isElementEqual(topElement, "java.io.FileOutputStream", "writeBytes")) {
plugin.getBlockActionManager().logCurrentStack("Server is performing {1} on the main thread. " +
"Properly caused by {0}", "java.io.FileStream");
}
}
}
}
示例4: isAnyThreadWorking
private boolean isAnyThreadWorking() {
LOG.info("Check if any thread is working and runnable.");
boolean someoneIsWorking = false;
for (int i = 0; i < threads.size(); i++) {
Thread thread = threads.get(i);
if (thread.isAlive() && thread.getState() == State.RUNNABLE) {
LOG.info("Thread " + i + " is working.");
someoneIsWorking = true;
}
}
return someoneIsWorking;
}
示例5: sanitize_enum
@Test
public void sanitize_enum() {
final State expected = State.RUNNABLE;
assertEquals(expected, new SanitizerForLists(expected).sanitize());
}
示例6: sanitize_enum
@Test
public void sanitize_enum() {
final State expected = State.RUNNABLE;
assertEquals(expected, new SanitizerForMaps(expected).sanitize());
}
示例7: update
public void update() throws Exception
{
boolean samplesAcquired = false;
for (ThreadInfo ti : threadMxBean_.dumpAllThreads(false, false))
{
long cpuTime = threadMxBean_.getThreadCpuTime(ti.getThreadId());
Long tCPUTime = threadCPUTime.get(ti.getThreadId());
if (tCPUTime == null)
{
tCPUTime = 0L;
}
else
{
Long deltaCpuTime = (cpuTime - tCPUTime);
if (ti.getStackTrace().length > 0
&& ti.getThreadState() == State.RUNNABLE
) {
for (StackTraceElement stElement : ti.getStackTrace()) {
if (isReallySleeping(stElement)) {
break;
}
if (isFiltered(stElement)) {
continue;
}
String key = stElement.getClassName() + "."
+ stElement.getMethodName();
data_.putIfAbsent(key, new MethodStats(stElement.getClassName(),
stElement.getMethodName()));
data_.get(key).getHits().addAndGet(deltaCpuTime);
totalThreadCPUTime_.addAndGet(deltaCpuTime);
samplesAcquired = true;
break;
}
}
}
threadCPUTime.put(ti.getThreadId(), cpuTime);
}
if (samplesAcquired)
{
updateCount_.incrementAndGet();
}
}
示例8: run
@Override
public void run() {
try {
while (runLogLoop) {
try {
final EventLogManager eventLogManager = EventLogManager.getInstance();
// Code inspiré de http://knight76.blogspot.fr/2009/05/how-to-get-java-cpu-usage-jvm-instance.html et http://www.docjar.com/html/api/sun/tools/jconsole/SummaryTab$Result.java.html
final SystemEventLog systemEventLog = eventLogManager.addEventLog(SystemEventLog.class);
final OperatingSystemMXBean osMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
final long processCpuTime = osMXBean.getProcessCpuTime();
final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
final long uptime = runtimeMXBean.getUptime();
final int availableProcessors = osMXBean.getAvailableProcessors();
final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
systemEventLog.setHeapMemoryUsed(memoryMXBean.getHeapMemoryUsage().getUsed());
systemEventLog.setNonHeapMemoryUsed(memoryMXBean.getNonHeapMemoryUsage().getUsed());
final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
systemEventLog.setThreadCount(threadMXBean.getThreadCount());
systemEventLog.setPeakThreadCount(threadMXBean.getPeakThreadCount());
// Compute the cpuUsage
if (prevUptime > 0L && uptime > prevUptime) {
// elapsedCpu is in ns and elapsedTime is in ms.
final long elapsedCpu = processCpuTime - prevProcessCpuTime;
final long elapsedTime = uptime - prevUptime;
// cpuUsage could go higher than 100% because elapsedTime
// and elapsedCpu are not fetched simultaneously. Limit to
// 99% to avoid Plotter showing a scale from 0% to 200%.
systemEventLog.setCpuUsage(Math.min(100F, elapsedCpu / (elapsedTime * 10000F * availableProcessors))); // elapsedCpu / (elapsedTime * 1000F * 1000F * availableProcessors)) * 100 => pour l'avoir en %
}
systemEventLog.setUptime(uptime);
systemEventLog.setProcessCpuTime(processCpuTime);
systemEventLog.setAvailableProcessors(availableProcessors);
// We now log all threads in RUNNABLE or BLOCKED state
final ThreadInfo[] allThreads = threadMXBean.dumpAllThreads(false, false);
final List<SystemEventLog.Thread> loggedThreads = new LinkedList<SystemEventLog.Thread>();
for (final ThreadInfo threadInfo : allThreads) {
if (threadInfo != null) { // It seems that sometime (with JRockit) threadInfo is null
final State threadState = threadInfo.getThreadState();
if ((threadState == State.BLOCKED || threadState == State.RUNNABLE) && PatternUtils.matches(threadInfo.getThreadName(), threadNameIncludes, threadNameExcludes)) {
final long threadId = threadInfo.getThreadId();
loggedThreads.add(new SystemEventLog.Thread(threadInfo, threadMXBean.getThreadUserTime(threadId), threadMXBean.getThreadCpuTime(threadId)));
}
}
}
systemEventLog.setBlockedOrRunningThreads(loggedThreads.toArray(new SystemEventLog.Thread[loggedThreads.size()]));
eventLogManager.fire(systemEventLog);
SystemEventLogger.this.prevUptime = uptime;
SystemEventLogger.this.prevProcessCpuTime = processCpuTime;
Thread.sleep(cpuComputationDeltaMillis);
} catch (final InterruptedException e) {
throw new RuntimeException(e);
}
}
} finally {
stop();
}
}
示例9: run
@Override
public void run() {
LOGGER.info(String.format("Monitoring cache update using thread %s; considers .lock age? %s",
Thread.currentThread().getId(),
maximumAge != Long.MIN_VALUE));
Map<Thread, StackTraceElement[]> stacks = Thread.getAllStackTraces();
Thread target = null;
/*
* try to find the
*/
if (TimerTaskCacheScheduler.this.lastSchedulerThread != Long.MIN_VALUE) {
for (Thread t : stacks.keySet()) {
if (t.getId() == TimerTaskCacheScheduler.this.lastSchedulerThread) {
target = t;
break;
}
}
}
if (target != null) {
State state = target.getState();
LOGGER.info("lastSchedulerThread status: " + state);
LOGGER.info("lastSchedulerThread isalive: " + target.isAlive());
LOGGER.info("lastSchedulerThread isinterrupted: " + target.isInterrupted());
if (state != State.RUNNABLE && state != State.BLOCKED) {
LOGGER.info(String.format("Updater thread's stack: %s", createStackTrace(target.getStackTrace())));
}
}
else {
LOGGER.warn("Could not find lastSchedulerThread in current stack traces");
}
boolean isLocked = true;
isLocked = isCurrentyLocked();
if (isLocked) {
if (target != null && (target.getState() == Thread.State.TIMED_WAITING
|| target.getState() == Thread.State.WAITING)) {
LOGGER.warn("The cache update may have taken too long. trying to interrupt cache update.");
target.interrupt();
}
try {
if (this.maximumAge != Long.MIN_VALUE) {
LOGGER.info("Resolving age of cache.lock file");
File f = resolveCacheLockFile();
if (System.currentTimeMillis() - f.lastModified() > this.maximumAge) {
LOGGER.info("Trying to remove artifact cache.lock file due to its age");
freeCacheUpdateLock();
}
else {
LOGGER.info("cache.lock to young, an update might be in progress.");
}
}
else if (TimerTaskCacheScheduler.this.lastSchedulerThread != Long.MIN_VALUE) {
/*
* only free if this CacheScheduler instance (singleton in an SOE instance)
* has already started a cache update. otherwise lastSchedulerThread has
* not been set yet
*/
LOGGER.info("freeing cache.lock");
freeCacheUpdateLock();
}
}
catch (IOException e) {
LOGGER.warn(e.getMessage(), e);
}
}
else {
LOGGER.info("No stale cache.lock file found.");
}
}