add a new thread pool,but not sure it's useful
[mfw.git] / src / mfw / pool / newer / MissionThreadAtom.java
blob6b3c6c939097a5a68b37448d9b9b965951d2a8a5
1 /**
2 * Copyright 2011 Huize Dai <geb.1989@gmail.com>
4 * This file is part of MFW.
6 * MFW is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * MFW is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with MFW. If not, see <http://www.gnu.org/licenses/>.
19 package mfw.pool.newer;
21 public class MissionThreadAtom extends Thread implements MissionThread {
23 private Runnable task = null;
24 private boolean isContinue = true;
26 MissionThreadAtom() {
29 public synchronized boolean run(Runnable task) {
30 if (task == null) {
31 this.task = task;
32 this.notify();
33 return true;
34 } else {
35 return false;
39 public void run() {
40 while (isContinue) {
41 synchronized (this) {
42 if (task == null) {
43 try {
44 this.wait();
45 } catch (InterruptedException ex) {
49 if (task != null) {
50 task.run();
51 task = null;
56 public synchronized void cancel() {
57 isContinue = true;
58 if (task == null)
59 this.notify();