最近写了几个演示DEMO,其中要用到暂停、继续功能。写了此类。 package thread; /** * Thread 抽象类,包含暂停/继续 * * @author lazybone * */ abstract class ZZQThread extends Thread { private int flag = 0;// 1 继续运行,2 暂停 ,3 停止 static final int start = 1; static final int pause = 2; static final int goon = 3; private Object o;// 同步锁 public ZZQThread() { o = new Object(); } abstract public void work(); // 需要子类实现的方法,类似 run() public void run() { flag = 1; while (flag == start) { try { work(); } catch (Exception e) { e.printStackTrace(); } while (flag == pause) { synchronized (o) { try { o.wait(); } catch (Exception e) { } } } } } public void stop_t() { flag = goon; } public void pause() { flag = pause; } public void goon() { flag = start; synchronized (o) { try { o.notify(); } catch (Exception e) { } } } }