本文整理汇总了Java中java.lang.Thread.State类的典型用法代码示例。如果您正苦于以下问题:Java State类的具体用法?Java State怎么用?Java State使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
State类属于java.lang.Thread包,在下文中一共展示了State类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toThreadState
import java.lang.Thread.State; //导入依赖的package包/类
/** 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: SampledThreadInfo
import java.lang.Thread.State; //导入依赖的package包/类
SampledThreadInfo(String tn, long tid, Thread.State ts, StackTraceElement[] st, InstrumentationFilter filter) {
threadName = tn;
threadId = tid;
state = ts;
stackTrace = st;
if (state == Thread.State.RUNNABLE && containsKnownBlockingMethod(st)) { // known blocking method -> change state to waiting
state = Thread.State.WAITING;
}
if (filter != null) {
int i;
for (i=0; i<st.length; i++) {
StackTraceElement frame = st[i];
if (filter.passes(frame.getClassName().replace('.','/'))) { // NOI18N
if (i>1) {
stackTrace = new StackTraceElement[st.length-i+1];
System.arraycopy(st,i-1,stackTrace,0,stackTrace.length);
}
break;
}
}
if (i==st.length) {
stackTrace = NO_STACK_TRACE;
}
}
}
示例3: testAddStacktraceWaitingPlus
import java.lang.Thread.State; //导入依赖的package包/类
@Test
public void testAddStacktraceWaitingPlus() {
System.out.println("add stacktrace : waiting/plus");
setState(stack0[0],Thread.State.WAITING);
addStacktrace(stack0, 0);
long timestamp = 500000;
setState(stackPlus[2],Thread.State.RUNNABLE);
addStacktrace(stackPlus, timestamp);
assertEquals(Math.max(stack0.length, stackPlus.length), instance.threadIds.size());
assertEquals(Math.max(elements0.length, elementsPlus.length), instance.methodInfos.size()-1);
assertEquals(timestamp, instance.currentDumpTimeStamp);
}
示例4: testAddStackTraceWaitRun
import java.lang.Thread.State; //导入依赖的package包/类
@Test
public void testAddStackTraceWaitRun() {
System.out.println("add stacktrace : wait->run");
addStacktrace(stack0, 0);
setState(stack0[0], Thread.State.WAITING);
addStacktrace(stack0, 500000);
assertEquals(500000, instance.currentDumpTimeStamp);
assertEquals(Thread.State.WAITING, instance.lastStackTrace.get().get(thread0.getId()).getThreadState());
setState(stack0[0], Thread.State.RUNNABLE);
addStacktrace(stack0, 1000000);
assertEquals(1000000, instance.currentDumpTimeStamp);
assertEquals(Thread.State.RUNNABLE, instance.lastStackTrace.get().get(thread0.getId()).getThreadState());
}
示例5: testAddStackTraceWaitWait
import java.lang.Thread.State; //导入依赖的package包/类
@Test
public void testAddStackTraceWaitWait() {
System.out.println("add stacktrace : wait->wait");
addStacktrace(stack0, 0);
setState(stack0[0], Thread.State.WAITING);
addStacktrace(stack0, 500000);
assertEquals(500000, instance.currentDumpTimeStamp);
assertEquals(Thread.State.WAITING, instance.lastStackTrace.get().get(thread0.getId()).getThreadState());
addStacktrace(stack0, 1000000);
assertEquals(1000000, instance.currentDumpTimeStamp);
assertEquals(Thread.State.WAITING, instance.lastStackTrace.get().get(thread0.getId()).getThreadState());
}
示例6: testAddStackTraceWaitBlocked
import java.lang.Thread.State; //导入依赖的package包/类
@Test
public void testAddStackTraceWaitBlocked() {
System.out.println("add stacktrace : wait->blocked");
addStacktrace(stack0, 0);
setState(stack0[0], Thread.State.WAITING);
addStacktrace(stack0, 500000);
assertEquals(500000, instance.currentDumpTimeStamp);
assertEquals(Thread.State.WAITING, instance.lastStackTrace.get().get(thread0.getId()).getThreadState());
setState(stack0[0], Thread.State.BLOCKED);
addStacktrace(stack0, 1000000);
assertEquals(1000000, instance.currentDumpTimeStamp);
assertEquals(Thread.State.BLOCKED, instance.lastStackTrace.get().get(thread0.getId()).getThreadState());
}
示例7: testGC
import java.lang.Thread.State; //导入依赖的package包/类
@Test
public void testGC() throws Exception {
CountDownLatch done = new CountDownLatch(1);
Scheduler scheduler = RxSchedulers.fixedSize(1);
FinalizeSupport.finalize(scheduler, done::countDown);
Wrapper<Thread> worker = Wrapper.empty();
Observable.just(1)
.subscribeOn(scheduler)
.doOnNext(i -> worker.set(Thread.currentThread()))
.blockingSubscribe();
scheduler = null;
System.gc();
assertTrue(done.await(100, TimeUnit.MILLISECONDS));
assertNotNull(worker.get());
for (int i = 0; i < 20; i++) {
System.gc();
Thread.sleep(5);
if (worker.get().getState() == State.TERMINATED) {
return;
}
}
assertEquals(State.TERMINATED, worker.get().getState());
}
示例8: put
import java.lang.Thread.State; //导入依赖的package包/类
/**
* Returns Cassandra driver session to sessions pool.
*
* @param cassandraSes Session wrapper.
* @param driverSes Driver session.
*/
public static void put(CassandraSessionImpl cassandraSes, Session driverSes) {
if (cassandraSes == null || driverSes == null) {
return;
}
SessionWrapper old;
synchronized (sessions) {
old = sessions.put(cassandraSes, new SessionWrapper(driverSes));
if (monitorSingleton == null || State.TERMINATED.equals(monitorSingleton.getState())) {
monitorSingleton = new SessionMonitor();
monitorSingleton.setDaemon(true);
monitorSingleton.setName("Cassandra-sessions-pool");
monitorSingleton.start();
}
}
if (old != null) {
old.release();
}
}
示例9: jobKillAll
import java.lang.Thread.State; //导入依赖的package包/类
/**
* 结束作业,包含子作业和转换 <br/>
* @author jingma
* @param job
*/
@SuppressWarnings("deprecation")
public static void jobKillAll(Job job){
job.stopAll();
JobMeta jobMeta = job.getJobMeta();
for(JobEntryCopy jec:jobMeta.getJobCopies()){
if(jec.isTransformation()){
JobEntryTrans jet = (JobEntryTrans)jec.getEntry();
if(jet.getTrans()!=null){
jet.getTrans().killAll();
}
}else if(jec.isJob()){
JobEntryJob jej = (JobEntryJob)jec.getEntry();
if(jej.getJob()!=null){
jobKillAll(jej.getJob());
}
}
}
//采用线程中断结束卡住的线程
if(job.getState().equals(State.BLOCKED)||job.getState().equals(State.TIMED_WAITING)){
job.stop();
}else{
job.interrupt();
}
}
示例10: sendOutofBandHeartBeat
import java.lang.Thread.State; //导入依赖的package包/类
/**
* This is to avoid race condition in the test case. NodeStatusUpdater
* heartbeat thread after sending the heartbeat needs some time to process the
* response and then go wait state. But in the test case once the main test
* thread returns back after resourceTracker.waitTillHeartbeat() we proceed
* with next sendOutofBandHeartBeat before heartbeat thread is blocked on
* wait.
* @throws InterruptedException
* @throws IOException
*/
private void sendOutofBandHeartBeat()
throws InterruptedException, IOException {
int i = 0;
do {
State statusUpdaterThreadState = ((NodeStatusUpdaterImpl) nm.getNodeStatusUpdater())
.getStatusUpdaterThreadState();
if (statusUpdaterThreadState.equals(Thread.State.TIMED_WAITING)
|| statusUpdaterThreadState.equals(Thread.State.WAITING)) {
nm.getNodeStatusUpdater().sendOutofBandHeartBeat();
break;
}
if (++i <= 10) {
Thread.sleep(50);
} else {
throw new IOException(
"Waited for 500 ms but NodeStatusUpdaterThread not in waiting state");
}
} while (true);
}
示例11: isReadable
import java.lang.Thread.State; //导入依赖的package包/类
public boolean isReadable() {
if (_thread == null) {
return true;
} else {
synchronized (_thread) {
if (_thread.getState() == State.WAITING) {
return true;
} else if (_thread.getState() == State.TIMED_WAITING) {
// Make sure that it stays readable
_tcx.waitUntilNotified(true);
return true;
}
return false;
}
}
}
示例12: start
import java.lang.Thread.State; //导入依赖的package包/类
private void start()
{
if( _thread == null || _thread.getState() == State.TERMINATED )
{
_isTerminated = false;
_thread = new Thread( this, _algorithm.name() + "." + _tcx.getTriangulationMode() );
_thread.start();
sendEvent( TriangulationProcessEvent.Started );
}
else
{
// Triangulation already running. Terminate it so we can start a new
shutdown();
_restart = true;
}
}
示例13: resume
import java.lang.Thread.State; //导入依赖的package包/类
public void resume()
{
if( _thread != null )
{
// Only force a resume when process is waiting for a notification
if( _thread.getState() == State.WAITING )
{
synchronized( _tcx )
{
_tcx.notify();
}
}
else if( _thread.getState() == State.TIMED_WAITING )
{
_tcx.waitUntilNotified( false );
}
}
}
示例14: isReadable
import java.lang.Thread.State; //导入依赖的package包/类
public boolean isReadable()
{
if( _thread == null )
{
return true;
}
else
{
synchronized( _thread )
{
if( _thread.getState() == State.WAITING )
{
return true;
}
else if( _thread.getState() == State.TIMED_WAITING )
{
// Make sure that it stays readable
_tcx.waitUntilNotified( true );
return true;
}
return false;
}
}
}
示例15: calculateLabel
import java.lang.Thread.State; //导入依赖的package包/类
private void calculateLabel() {
StringBuilder str = new StringBuilder();
str.append("[");
for(Entry<Thread.State, Integer> entry:states.entrySet()) {
str.append(entry.getKey());
str.append(" ");
try {
BigDecimal percentage = new BigDecimal((100.0*entry.getValue())/sampleCount);
percentage = percentage.setScale(0,RoundingMode.HALF_EVEN);
str.append(percentage);
} catch (Exception e) {
logger.error("Error while calculation label "+str.toString(),e);
}
str.append("% ");
}
str.append("]");
label = name + str.toString();
}