Java Code Examples for java.lang.Thread.State#TERMINATED

The following examples show how to use java.lang.Thread.State#TERMINATED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OverviewController.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** 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;
    }
}
 
Example 2
Source File: OverviewController.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
/** 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;
    }
}
 
Example 3
Source File: Threads.java    From glowroot with Apache License 2.0 6 votes vote down vote up
public static List<Thread> currentThreads() {
    List<Thread> threads = Lists.newArrayList();
    for (Thread thread : Thread.getAllStackTraces().keySet()) {
        // DestroyJavaVM is a JVM thread that appears sporadically, easier to just filter it out
        //
        // AWT-AppKit is a JVM thread on OS X that appears during webdriver tests
        //
        // "process reaper" are JVM threads on linux that monitors subprocesses, these use a
        // thread pool in jdk7 and so the threads stay around in the pool even after the
        // subprocess ends, they show up here when mixing local container and javaagent
        // container tests since javaagent container tests create subprocesses and then local
        // container tests check for rogue threads and find these
        if (thread.getState() != State.TERMINATED
                && !thread.getName().equals("DestroyJavaVM")
                && !thread.getName().equals("AWT-AppKit")
                && !thread.getName().equals("process reaper")) {
            threads.add(thread);
        }
    }
    return threads;
}
 
Example 4
Source File: AbstractCustomView.java    From java-photoslibrary with Apache License 2.0 5 votes vote down vote up
/** Updates the view in a new thread and shows loading indicator. */
public final void updateView() {
  synchronized (updateLock) {
    if ((updateThread == null || updateThread.getState() == State.TERMINATED)
        && initializationThread.getState() == State.TERMINATED) {
      updateThread = getUpdateThread();
      loadingView.showView();
      updateThread.start();
    } else {
      rerunUpdate = true;
    }
  }
}
 
Example 5
Source File: AndroidDebugBridge.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns whether the {@link AndroidDebugBridge} object is still connected to the adb daemon.
 */
public boolean isConnected() {
    MonitorThread monitorThread = MonitorThread.getInstance();
    if (mDeviceMonitor != null && monitorThread != null) {
        return mDeviceMonitor.isMonitoring() && monitorThread.getState() != State.TERMINATED;
    }
    return false;
}
 
Example 6
Source File: SaturativeExecutor.java    From ACDD with MIT License 5 votes vote down vote up
protected boolean isSaturated() {
    if (getPoolSize() <= 3) {
        return DEBUG;
    }
    int corePoolSize = getCorePoolSize();
    int i = CountedTask.mNumRunning.get();
    int size = mThreads.size();
    if (i < corePoolSize || i < size) {
        return true;
    }
    boolean z;
    synchronized (mThreads) {
        Iterator<Thread> it = mThreads.iterator();
        size = 0;
        while (it.hasNext()) {
            State state = it.next().getState();
            if (state == State.RUNNABLE || state == State.NEW) {
                i = size + 1;
            } else {
                if (state == State.TERMINATED) {
                    it.remove();
                }
                i = size;
            }
            size = i;
        }
    }
    z = size >= corePoolSize;
    return z;
}
 
Example 7
Source File: MediaLibrary.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
public void scanMediaItems() {
    if (mLoadingThread == null || mLoadingThread.getState() == State.TERMINATED) {
        isStopping = false;
        Util.actionScanStart();
        mLoadingThread = new Thread(new GetMediaItemsRunnable());
        mLoadingThread.start();
    }
}
 
Example 8
Source File: MediaLibrary.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
public boolean isWorking() {
    if (mLoadingThread != null &&
        mLoadingThread.isAlive() &&
        mLoadingThread.getState() != State.TERMINATED &&
        mLoadingThread.getState() != State.NEW)
        return true;
    return false;
}
 
Example 9
Source File: Thumbnailer.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
public void start(IVideoBrowser videoBrowser) {
    isStopping = false;
    if (mThread == null || mThread.getState() == State.TERMINATED) {
        mVideoBrowser = new WeakReference<IVideoBrowser>(videoBrowser);
        mThread = new Thread(this);
        mThread.start();
    }
}
 
Example 10
Source File: GuidTest.java    From alfresco-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Tests the improvement added by using a SecureRandom pool when generating GUID's 
 */
public void testGuid()
{
    // warm-up (to pre-init the secureRandomArray)
    GUID.generate();

    List<Thread> threads = new ArrayList<>();
    int n = 30;
    
    for (int i = 0; i < n; i++)
    {
        Thread thread = new Thread(new GuidRunner());
        threads.add(thread);
        thread.start();
    }
    
    Set<String> blocked = new HashSet<String>();
    Set<String> terminated = new HashSet<String>();

    int maxItemsBlocked = 0;

    while (terminated.size() != n)
    {
        for (Thread current : threads)
        {
            State state = current.getState();
            String name = current.getName();

            if (state == State.BLOCKED)
            {
                if (!blocked.contains(name))
                {
                    blocked.add(name);
                    maxItemsBlocked = blocked.size() > maxItemsBlocked ? blocked.size() : maxItemsBlocked;
                }
            }
            else // not BLOCKED, eg. RUNNABLE, TERMINATED, ...
            {
                blocked.remove(name);
                if (state == State.TERMINATED && !terminated.contains(name))
                {
                    terminated.add(name);
                }
            }
        }
    }
    
    //worst case scenario : max number of threads blocked at a moment = number of threads - 2 ( usually ~5 for 30 threads)
    //the implementation without RandomSecure pool reaches constantly (number of threads - 1) max blocked threads  
    Assert.assertTrue("Exceeded number of blocked threads : " + maxItemsBlocked, maxItemsBlocked < n-2);
}
 
Example 11
Source File: ThreadCommand.java    From xunxian with Apache License 2.0 4 votes vote down vote up
/**
 * 开启打怪线程
 * 自动检索线程是否开启,若没开启,则全部重新开启。若开启后没有执行完毕,则继续使用
 */
public void startDaGuaiThread(){
	Command.mainThread=true;	//线程运行状态开启
	try {
		if(Command.logThread.getState()==State.TERMINATED){
			Command.logThread=null;
			Command.logThread=new LogThread();
			Command.logThread.start();
			new Func.File().log("日志线程启动");
		}
		if(Command.daGuaiThread.getState()==State.TERMINATED){
			Command.daGuaiThread=null;
			Command.daGuaiThread=new DaGuaiThread();
			Command.daGuaiThread.start();
			new Func.File().log("打怪主线程启动");
		}
		if(Command.systemThread.getState()==State.TERMINATED){
			Command.systemThread=null;
			Command.systemThread=new SystemThread();
			Command.systemThread.start();
			new Func.File().log("系统线程启动");
		}
	} catch (Exception e) {		//捕获异常,可能是线程未初始化,进行初始化线程并开启
		if(e.getMessage()!=null){
			new Func.File().log("线程初始化开启");
		}
		
		Command.daGuaiThread=new DaGuaiThread();
		Command.logThread=new LogThread();
		Command.systemThread=new SystemThread();
		
		Command.daGuaiThread.start();
		new Func.File().log("打怪主线程启动");
		Command.logThread.start();
		new Func.File().log("日志线程启动");
		Command.systemThread.start();
		new Func.File().log("系统线程启动");
	}
	
	
	Command.daGuaiThread.setPriority(1);	//打怪主线程优先级最低
	Command.logThread.setPriority(1);		//日志线程,最低
	Command.systemThread.setPriority(8);	//系统线程最高
	
	Command.daGuaiThread.setName("打怪主线程");
	Command.logThread.setName("日志线程");
	Command.systemThread.setName("系统线程");
}
 
Example 12
Source File: ThreadCommand.java    From xunxian with Apache License 2.0 4 votes vote down vote up
/**
 * 定点开鼓
 */
public void startSettledOpenGuThread(){
	Command.mainThread=true;	//线程运行状态开启
	try {
		if(Command.logThread.getState()==State.TERMINATED){
			Command.logThread=null;
			Command.logThread=new LogThread();
			Command.logThread.start();
			new Func.File().log("日志线程启动");
		}
		if(Command.settledOpenThread.getState()==State.TERMINATED){
			Command.settledOpenThread=null;
			Command.settledOpenThread=new SettledOpenThread();
			Command.settledOpenThread.start();
			new Func.File().log("定点扫描鼓主线程启动");
		}
		if(Command.systemThread.getState()==State.TERMINATED){
			Command.systemThread=null;
			Command.systemThread=new SystemThread();
			Command.systemThread.start();
			new Func.File().log("系统线程启动");
		}
	} catch (Exception e) {		//捕获异常,可能是线程未初始化,进行初始化线程并开启
		if(e.getMessage()!=null){
			new Func.File().log("线程初始化开启");
		}
		
		Command.settledOpenThread=new SettledOpenThread();
		Command.logThread=new LogThread();
		Command.systemThread=new SystemThread();
		
		Command.settledOpenThread.start();
		new Func.File().log("打怪主线程启动");
		Command.logThread.start();
		new Func.File().log("日志线程启动");
		Command.systemThread.start();
		new Func.File().log("系统线程启动");
	}
	
	
	Command.settledOpenThread.setPriority(1);	//打怪主线程优先级最低
	Command.logThread.setPriority(1);		//日志线程,最低
	Command.systemThread.setPriority(8);	//系统线程最高
	
	Command.settledOpenThread.setName("定点开鼓主线程");
	Command.logThread.setName("日志线程");
	Command.systemThread.setName("系统线程");
}
 
Example 13
Source File: ThreadCommand.java    From xunxian with Apache License 2.0 4 votes vote down vote up
/**
 * 自动扫货
 */
public void startSaoHuoThread(){
	Command.mainThread=true;
	try{
		if(Command.saoHuoThread.getState()==State.TERMINATED){
			Command.saoHuoThread=null;
			Command.saoHuoThread=new SaoHuoThread();
			Command.saoHuoThread.start();
			new Func.File().log("扫货主线程启动");
		}
		if(Command.logThread.getState()==State.TERMINATED){
			Command.logThread=null;
			Command.logThread=new LogThread();
			Command.logThread.start();
			new Func.File().log("日志线程启动");
		}
		if(Command.systemThread.getState()==State.TERMINATED){
			Command.systemThread=null;
			Command.systemThread=new SystemThread();
			Command.systemThread.start();
			new Func.File().log("系统线程启动");
		}
	}catch (Exception e) {
		if(e.getMessage()!=null){
			new Func.File().log("扫货线程开启异常捕获:"+e.getMessage());
		}
		
		Command.saoHuoThread=new SaoHuoThread();
		Command.saoHuoThread.start();
		new Func.File().log("扫货主线程启动");

		Command.logThread=new LogThread();
		Command.logThread.start();
		new Func.File().log("日志线程启动");
		
		Command.systemThread=new SystemThread();
		Command.systemThread.start();
		new Func.File().log("系统线程启动");

	}
	
	Command.saoHuoThread.setName("扫货主线程");
	Command.saoHuoThread.setPriority(7);		//监控优先级高!
	
	Command.logThread.setName("日志线程");
	Command.logThread.setPriority(1);			//日志线程最低
	
	Command.systemThread.setName("系统线程");
	Command.systemThread.setPriority(8);			//系统线程优先级最高
	
}