本文整理汇总了Java中java.lang.Thread.State.WAITING属性的典型用法代码示例。如果您正苦于以下问题:Java State.WAITING属性的具体用法?Java State.WAITING怎么用?Java State.WAITING使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.lang.Thread.State
的用法示例。
在下文中一共展示了State.WAITING属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: waitForInitialization
private void waitForInitialization(long threadID) throws InterruptedException {
ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
boolean isWaiting = true;
while (isWaiting) {
ThreadInfo threadInfo = mbean.getThreadInfo(threadID);
if (threadInfo == null) {
Thread.sleep(50);
continue;
}
if (threadInfo.getThreadState() == State.WAITING)
isWaiting = false;
else
Thread.sleep(50);
}
}
示例6: setNewDataWorker
private void setNewDataWorker() {
if (this.dataThread != null) {
this.dataWorker.induceStop();
if (this.dataThread != Thread.currentThread()) {
State state = this.dataThread.getState();
if (state == State.BLOCKED || state == State.WAITING)
this.dataThread.interrupt();
}
}
this.dataTasks = new LinkedBlockingQueue<DataTask>();
this.dataWorker = new DataWorker(this, this.currentSession, this.dataTasks);
this.dataThread = new Thread(dataWorker);
this.dataThread.setName("Data Worker for " + this.currentSession);
this.dataThread.start();
}
示例7: getThreadDebugData
/** Returns an array list of debug information for all Java threads; useful for trying to diagnose the cause of odd behaviour.
*
* @return An array list of debug information
*/
public static ArrayList<String> getThreadDebugData()
{
ArrayList<String> strings = new ArrayList<String>();
strings.add("------------------------------------------------------------");
strings.add("Debugging information for Java virtual machine");
ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
for (ThreadInfo thread : threads)
{
if (thread.getThreadState() != State.WAITING)
{
strings.add("------------------------------------------------------------");
strings.add(thread.getThreadName());
strings.add("\tPID: " + thread.getThreadId() + " | Suspended: " + thread.isSuspended() + " | Native: " + thread.isInNative() + " | State: " + thread.getThreadState());
if (thread.getLockedMonitors().length != 0)
{
strings.add("\tThread is waiting on monitor(s):");
for (MonitorInfo monitor : thread.getLockedMonitors())
{
strings.add("\t\tLocked on:" + monitor.getLockedStackFrame());
}
}
strings.add("\tStack trace:");
StackTraceElement[] stack = thread.getStackTrace();
for (int line = 0; line < stack.length; line++)
{
strings.add("\t\t" + stack[line].toString());
}
}
}
strings.add("------------------------------------------------------------");
strings.add("End of debugging information");
strings.add("------------------------------------------------------------");
return strings;
}
示例8: 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);
}
}
}
示例9: isWaiting
public boolean isWaiting()
{
if( _thread != null && _thread.getState() == State.WAITING )
{
return true;
}
return false;
}
示例10: checkActionIsPrepared
private boolean checkActionIsPrepared() {
if (WifiReceiver.getInstance().isConnected()
&& ServiceManager.getInstance().isDmcOpen()) {
if (Thread.currentThread().getState() == State.WAITING) {
return false;
}
return true;
} else {
return false;
}
}
示例11: 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);
}
示例12: shutdownThreads
public static void shutdownThreads() {
if (persistenceThread != null) {
worker.induceStop();
State state = persistenceThread.getState();
int tasks = worker.getNumTasks();
if (tasks == 0 && (state == State.BLOCKED || state == State.WAITING))
persistenceThread.interrupt();
persistenceThread = null;
}
}
示例13: requestImgDownload
public void requestImgDownload(String img_url, boolean fullScreen, TAImageDataHandler handler){
try{
Queue<doImgDownloadElem> msgs = imgDownThread.getpMsgs();
doImgDownloadElem elem = new doImgDownloadElem(img_url, handler);
elem.setFullScreen(fullScreen);
msgs.add(elem);
if(imgDownThread.getState() == State.WAITING){
synchronized (msgs) {
msgs.notify();
}
}
}catch(final Exception ex){
ex.printStackTrace();
}
}
示例14: isWaiting
public boolean isWaiting() {
if (_thread != null && _thread.getState() == State.WAITING) {
return true;
}
return false;
}
示例15: run
@Override
public void run() {
ExecutorService executorService = ThreadPool.pool;
while (true) {
Thread[] leastThreads = new Thread[Thread.activeCount()];
int length = Thread.enumerate(leastThreads);
boolean isAllWaiting = false;
for (int i = 0; i < leastThreads.length; i++) {
Thread thread = leastThreads[i];
System.out.println("thread: " + thread.toString());
System.out.println(thread.getState());
System.out.println("thread.getState() == State.WAITING: "
+ (thread.getState() == State.WAITING));
if (thread.getName().startsWith("pool")) {
if (thread.getState() == State.WAITING) {
isAllWaiting = true;
// thread.interrupt();
// System.out.println("等待线程结束:" + thread);
} else {
isAllWaiting = false;
}
}
// System.out.println(Thread.currentThread().getId());
}
if (isAllWaiting) {
executorService.shutdownNow();
if (executorService.isShutdown()) {
System.out.println("pool.isShutdown() ================= "
+ executorService.isShutdown());
shutDowned();
return;
}
}
try {
Thread.currentThread().sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}