一个可安全挂起,恢复的线程

xiaoxiao2021-02-28  76

本线程是一个自己封装的java线程,直接看代码,不懂请留言


public abstract class CustomThread {

private Thread thread; protected boolean running = true; protected volatile boolean suspendFlag; public CustomThread() { thread = new Thread() { @Override public void run() { super.run(); threadPro(); } }; } public void suspend() { suspendFlag = true; } public synchronized void resume() { suspendFlag = false; notify(); } public boolean isSuspended() { return suspendFlag; } public Thread getThread() { return thread; } public void startThread() { thread.start(); } public boolean getActived() { return thread.isAlive(); } public void setPriority(int priority) { thread.setPriority(priority); } public int getPriority() { return thread.getPriority(); } public long getThreadId() { return thread.getId(); } public void destory() { running = false; } public abstract void threadPro();

}

转载请注明原文地址: https://www.6miu.com/read-53914.html

最新回复(0)