本文整理匯總了Java中java.lang.Thread.State.TIMED_WAITING屬性的典型用法代碼示例。如果您正苦於以下問題:Java State.TIMED_WAITING屬性的具體用法?Java State.TIMED_WAITING怎麽用?Java State.TIMED_WAITING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類java.lang.Thread.State
的用法示例。
在下文中一共展示了State.TIMED_WAITING屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: isReadable
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;
}
}
}
示例3: resume
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 );
}
}
}
示例4: isReadable
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;
}
}
}
示例5: resume
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);
}
}
}
示例6: unsafe_prepend
/** Only to be used for prepending data that was not successfully written, and was just pulled out. No other use is safe. */
protected void unsafe_prepend(byte[] buf, int offset, int length) {
synchronized (this.buf) {
System.arraycopy(buf, offset, this.buf, this.read - length, length);
this.read -= length;
this.length += length;
}
if (flushInterrupt != null && flushInterrupt.getState() == State.TIMED_WAITING) {
synchronized (flushInterrupt) {
flushInterrupt.notify();
}
}
}
示例7: TimeoutError
public TimeoutError() {
this.state = mainThread.getState();
StackTraceElement[] trace = mainThread.getStackTrace();
try {
if ((state == State.WAITING) || (state == State.TIMED_WAITING)) {
List<StackTraceElement> elements = new ArrayList<StackTraceElement>(Arrays.asList(trace));
long ownerId = mainThread.getId();
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
ThreadInfo threadInfo = null;
long nextId = ownerId;
while (nextId != -1) {
threadInfo = bean.getThreadInfo(nextId, Integer.MAX_VALUE);
if (threadInfo == null) {
break; // the thread being blocked on has terminated
}
nextId = threadInfo.getLockOwnerId();
if (nextId == ownerId) {
break;
}
String threadName = threadInfo.getThreadName();
elements.add(new StackTraceElement(TimeoutError.class.getCanonicalName(), "THREAD_" + threadName, "STACK$TRACE", 1));
elements.addAll(Arrays.asList(threadInfo.getStackTrace()));
if (nextId == -1) {
break;
}
}
trace = elements.toArray(trace);
}
} catch (Exception e) {
LogUtil.error(e);
}
StackTraceElement[] newTrace = new StackTraceElement[trace.length+1];
newTrace[0] = new StackTraceElement(TimeoutError.class.getCanonicalName(), "ESTIMATED", "STACK$TRACE", 1);
System.arraycopy(trace, 0, newTrace, 1, trace.length);
setStackTrace(trace);
}
示例8: waken
public void waken() {
if (currentthread.getState() == State.TIMED_WAITING) {
currentthread.interrupt();
}
}