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

来源:互联网 发布:手机dns修复软件 编辑:程序博客网 时间:2024/05/21 19:37

本线程是一个自己封装的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();

}

原创粉丝点击