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


Java State类代码示例

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

示例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;
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:StackTraceSnapshotBuilder.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:StackTraceSnapshotBuilderTest.java

示例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());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:StackTraceSnapshotBuilderTest.java

示例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());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:StackTraceSnapshotBuilderTest.java

示例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());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:StackTraceSnapshotBuilderTest.java

示例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());
}
 
开发者ID:XDean,项目名称:Java-EX,代码行数:24,代码来源:RxSchedulersTest.java

示例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();
    }
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:25,代码来源:SessionPool.java

示例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();
    }
}
 
开发者ID:majinju,项目名称:KettleEasyExpand,代码行数:30,代码来源:KettleUtils.java

示例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);
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:30,代码来源:TestNodeStatusUpdaterForLabels.java

示例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;
    }
  }
}
 
开发者ID:perunlabs,项目名称:jsolid,代码行数:17,代码来源:TriangulationProcess.java

示例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;
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:17,代码来源:TriangulationProcess.java

示例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 );
        }
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:TriangulationProcess.java

示例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;
        }
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:25,代码来源:TriangulationProcess.java

示例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();
	}
 
开发者ID:denkbar,项目名称:djigger,代码行数:20,代码来源:ThreadBlock.java


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