User: jung
Date: 00/12/22 00:34:50
Modified: src/de/infor/ce/util ThreadPool.java
Log:
began with exception redesign (messages+embedded throwables).
added a convenient logger console abstraction.
generic Environment.java for configuring packages.
some refactoring of the http package
began move to LGPL
Revision Changes Path
1.3 +5 -165 zoap/src/de/infor/ce/util/ThreadPool.java
Index: ThreadPool.java
===================================================================
RCS file: /products/cvs/ejboss/zoap/src/de/infor/ce/util/ThreadPool.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ThreadPool.java 2000/12/04 12:35:51 1.2
+++ ThreadPool.java 2000/12/22 08:34:49 1.3
@@ -1,5 +1,5 @@
/*
- * $Id: ThreadPool.java,v 1.2 2000/12/04 12:35:51 jung Exp $
+ * $Id: ThreadPool.java,v 1.3 2000/12/22 08:34:49 jung Exp $
* Copyright 2000 (C) infor:business solutions AG, Hauerstrasse 12,
* D-66299 Friedrichsthal, Germany. All Rights Reserved.
*
@@ -144,7 +144,9 @@
active++;
// when creating such a thread, it is started immediately
- new PooledThread(runnable).start();
+ PooledThread newThread=new PooledThread(this,runnable,threadName);
+ newThread.setDaemon(daemon);
+ newThread.start();
} // if(doesBlock())
@@ -197,7 +199,7 @@
* return into the pool
*/
- private void returnThread(PooledThread thread) {
+ void returnThread(PooledThread thread) {
if(Environment.DEBUG_UTIL && Environment.DEBUG_THREADPOOL)
Environment.out.println(toString()+".returnThread("+thread+")");
@@ -218,177 +220,6 @@
} // returnPooledThread
- /**
- * inner class that implements poolable threads
- */
- private class PooledThread {
-
- /** should this thread keep on running? */
- private boolean running;
-
- /** what would be the next task to perform? */
- private Runnable runnable;
-
- /** you can equip a pooled thread with a runnable at creation time */
- PooledThread(Runnable runnable) {
-
- if(Environment.DEBUG_UTIL && Environment.DEBUG_THREADPOOL)
- Environment.out.println(this.toString()+"("+runnable+")");
-
- running=true;
- this.runnable=runnable;
- }
-
- public void start()
- {
-
- if(Environment.DEBUG_UTIL && Environment.DEBUG_THREADPOOL)
- Environment.out.println(this.toString()+".start()");
-
- Thread newThread=new Thread(threadName) {
- public void run() {
- PooledThread.this.run();
-
- if(Environment.DEBUG_UTIL && Environment.DEBUG_THREADPOOL)
- Environment.out.println(this.toString()+"-.start():"+
- " coming to end.");
-
- }
- };
-
- newThread.setDaemon(daemon);
-
- newThread.start();
-
- }
-
- /**
- * do something
- * meaningful over a longer period of time
- */
-
- private void run() {
-
- if(Environment.DEBUG_UTIL && Environment.DEBUG_THREADPOOL)
- Environment.out.println(this.toString()+".run()");
-
- while (running) {
-
- if (runnable != null) {
-
- try {
- runnable.run();
- } catch (Exception e) {
- // catch any internal exception to continue
working
- }
-
- // Clear work, this is safe as the thread
should be non-pooled in this state
- runnable = null;
- }
-
- // Return to pool
- returnThread(this);
-
- if(Environment.DEBUG_UTIL && Environment.DEBUG_THREADPOOL)
- Environment.out.println(this.toString()+".run():"+
- " going to sleep.");
-
- // Wait for work to become available
- synchronized (this) {
- if(running && runnable==null) {
- try {
- this.wait();
- } catch (InterruptedException e){
- }
- }
- }
-
- if(Environment.DEBUG_UTIL && Environment.DEBUG_THREADPOOL)
- Environment.out.println(this.toString()+".run(): awake.");
-
- } // while
-
- if(Environment.DEBUG_UTIL && Environment.DEBUG_THREADPOOL)
- Environment.out.println(this.toString()+".run(): dead.");
-
- } // run
-
- /**
- * this method allows to start an arbitrary runnable in this thread,
- * is guarantueed to run only once
- */
-
- public void run(Runnable runnable) {
-
- if(Environment.DEBUG_UTIL && Environment.DEBUG_THREADPOOL)
- Environment.out.println(this.toString()+".run("+runnable+")");
-
- synchronized(this) {
- if(running && this.runnable==null) {
-
- if(Environment.DEBUG_UTIL && Environment.DEBUG_THREADPOOL)
- Environment.out.print(this.toString()+".run("+runnable+"): has
lock.\n");
-
- this.runnable = runnable;
- this.notify();
- } else {
- // this should never, never happen
- throw new RuntimeException("Could not run runnable on because pooled
thread is dead or occupied.");
- }
- }
- }
-
- /** and finally, the signal to die ASAP */
- public void finalize() {
-
- if(Environment.DEBUG_UTIL && Environment.DEBUG_THREADPOOL)
- Environment.out.println(this.toString()+".finalize()");
-
- synchronized(this) {
- if(running && runnable==null) {
-
- if(Environment.DEBUG_UTIL && Environment.DEBUG_THREADPOOL)
- Environment.out.print(this.toString()+".finalize(): has lock.\n");
-
- running = false;
- this.notify();
- } else {
- throw new RuntimeException("could not finalize finalized or tasked thread");
- } // if
- } // sync
- } // die
-
- } // PooledThread
-
} // ThreadPool
-
-/*
- * $Log: ThreadPool.java,v $
- * Revision 1.2 2000/12/04 12:35:51 jung
- * adopted to latest jboss container,
- *
- * added decimal and date
- *
- * removed some problems due to forward-referencing in meta-data
- *
- * added serialisation policy
- *
- * Revision 1.1.1.1 2000/08/10 21:06:48 jung
- * Initial import.
- *
- *
- * Revision 1.1.1.1.2.1 2000/07/13 12:46:17 jung
- * package renaming, most of the zoap stuff now under org.zoap
- * util and http stay infor.ce, containerInvoker etc move to org.jboss
- *
- * changed the makefile, adopted most of the licenses
- *
- * Revision 1.1.1.1 2000/07/06 14:11:27 jung
- * Import of a pre beta version of ZOAP source with a new directory structure,
- * ant-based make, apache-kind of license, etc.
- *
- * jars are coming later because of cvs-history reasons.
- *
- */