本文整理匯總了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();
}