Revision: 2338
http://sourceforge.net/p/swingme/code/2338
Author: yuranet
Date: 2015-03-06 01:00:09 +0000 (Fri, 06 Mar 2015)
Log Message:
-----------
better thread pool
Modified Paths:
--------------
UtilME/src/net/yura/mobile/util/QueueProcessorThread.java
Modified: UtilME/src/net/yura/mobile/util/QueueProcessorThread.java
===================================================================
--- UtilME/src/net/yura/mobile/util/QueueProcessorThread.java 2015-01-03 01:35:31 UTC (rev 2337)
+++ UtilME/src/net/yura/mobile/util/QueueProcessorThread.java 2015-03-06 01:00:09 UTC (rev 2338)
@@ -11,7 +11,7 @@
public static boolean CHANGE_PRIORITY=true;
private Vector inbox = new Vector();
- private boolean runnning;
+ private boolean running;
private Vector threads = new Vector(1);
public QueueProcessorThread(String name) {
@@ -30,6 +30,7 @@
}
public void start() {
+ running = true;
for (int c=0;c<threads.size();c++) {
((Thread)threads.elementAt(c)).start();
}
@@ -37,11 +38,15 @@
/**
* @see java.util.concurrent.ExecutorService#shutdown()
+ * @see java.util.concurrent.ExecutorService#shutdownNow()
*/
public void kill() {
synchronized(this) {
- runnning = false;
+ running = false;
notifyAll();
+ //for (int c=0;c<threads.size();c++) {
+ // ((Thread)threads.elementAt(c)).interrupt();
+ //}
}
}
@@ -63,26 +68,18 @@
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
}
- runnning = true;
+ runLoop: while (running) {
- runLoop: while (runnning) {
-
Object object=null;
try {
synchronized(this) {
while(inbox.isEmpty()) {
- if (!runnning) {
+ if (!running) {
break runLoop;
}
- try {
- wait();
- }
- catch (InterruptedException ex) {
- Logger.info(null, ex);
- // TODO do something!!!!
- }
+ wait();
}
object = inbox.elementAt(0);
inbox.removeElementAt(0);
@@ -102,6 +99,9 @@
Thread.sleep(0);
}
}
+ catch(InterruptedException ex) {
+ break runLoop;
+ }
catch (Exception ex) {
//#debug warn
Logger.warn("[QueueProcessorThread-" + Thread.currentThread().getName() + "] error processing "+object, ex);
@@ -116,6 +116,7 @@
/**
* @see java.util.concurrent.Executor#execute(java.lang.Runnable)
+ * @see java.util.concurrent.ExecutorService#submit(java.lang.Runnable)
*/
public void addToInbox(Object obj) {
synchronized(this) {
@@ -124,8 +125,11 @@
}
}
+ /**
+ * @see java.util.concurrent.ExecutorService#isShutdown()
+ */
public boolean isRunning() {
- return runnning;
+ return running;
}
public void clearInbox() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|