当前位置: 首页>>代码示例>>Java>>正文


Java State.RUNNABLE属性代码示例

本文整理汇总了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;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:OverviewController.java

示例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;
}
 
开发者ID:bunnyblue,项目名称:ACDD,代码行数:30,代码来源:SaturativeExecutor.java

示例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");
            }
        }
    }
}
 
开发者ID:games647,项目名称:LagMonitor,代码行数:29,代码来源:BlockingIODetectorTask.java

示例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;
}
 
开发者ID:eduardoguzman,项目名称:sisob-data-extractor,代码行数:12,代码来源:CrawlController.java

示例5: sanitize_enum

@Test
public void sanitize_enum() {
    final State expected = State.RUNNABLE;
    assertEquals(expected, new SanitizerForLists(expected).sanitize());
}
 
开发者ID:bxfsh,项目名称:boxfish-commons-web-model,代码行数:5,代码来源:SanitizerForListsTest.java

示例6: sanitize_enum

@Test
public void sanitize_enum() {
    final State expected = State.RUNNABLE;
    assertEquals(expected, new SanitizerForMaps(expected).sanitize());
}
 
开发者ID:bxfsh,项目名称:boxfish-commons-web-model,代码行数:5,代码来源:SanitizerForMapsTest.java

示例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();
}
  }
 
开发者ID:patric-r,项目名称:jvmtop,代码行数:43,代码来源:CPUSampler.java

示例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();
	}
}
 
开发者ID:iorga-group,项目名称:webapp-watcher,代码行数:60,代码来源:SystemEventLogger.java

示例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.");
	}
	
}
 
开发者ID:52North,项目名称:ArcGIS-Server-SOS-Extension,代码行数:78,代码来源:TimerTaskCacheScheduler.java


注:本文中的java.lang.Thread.State.RUNNABLE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。