summaryrefslogtreecommitdiff
path: root/java/src/IceInternal/ThreadPool.java
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2003-01-29 21:36:36 +0000
committerMarc Laukien <marc@zeroc.com>2003-01-29 21:36:36 +0000
commit8ddb737ceb588e6a174870b5712a6cbb2275e8a4 (patch)
tree6fb4cac9ef3c618e91bee6c56159959b76f3689b /java/src/IceInternal/ThreadPool.java
parentfix (diff)
downloadice-8ddb737ceb588e6a174870b5712a6cbb2275e8a4.tar.bz2
ice-8ddb737ceb588e6a174870b5712a6cbb2275e8a4.tar.xz
ice-8ddb737ceb588e6a174870b5712a6cbb2275e8a4.zip
ServantManager; pool-per-adapter; fixes
Diffstat (limited to 'java/src/IceInternal/ThreadPool.java')
-rw-r--r--java/src/IceInternal/ThreadPool.java220
1 files changed, 102 insertions, 118 deletions
diff --git a/java/src/IceInternal/ThreadPool.java b/java/src/IceInternal/ThreadPool.java
index 4374d3067ab..d265d309b4b 100644
--- a/java/src/IceInternal/ThreadPool.java
+++ b/java/src/IceInternal/ThreadPool.java
@@ -24,112 +24,12 @@ public final class ThreadPool
private final static boolean TRACE_THREAD = false;
private final static boolean TRACE_STACK_TRACE = false;
- public synchronized void
- _register(java.nio.channels.SelectableChannel fd, EventHandler handler)
- {
- if(TRACE_REGISTRATION)
- {
- trace("adding handler of type " + handler.getClass().getName() + " for channel " + fd);
- }
- assert(!_destroyed);
- _changes.add(new FdHandlerPair(fd, handler));
- setInterrupt(0);
- }
-
- public synchronized void
- unregister(java.nio.channels.SelectableChannel fd)
- {
- if(TRACE_REGISTRATION)
- {
- if(TRACE_STACK_TRACE)
- {
- java.io.StringWriter sw = new java.io.StringWriter();
- try
- {
- throw new RuntimeException();
- }
- catch(RuntimeException ex)
- {
- java.io.PrintWriter pw = new java.io.PrintWriter(sw);
- ex.printStackTrace(pw);
- pw.flush();
- }
- trace("removing handler for channel " + fd + "\n" + sw.toString());
- }
- else
- {
- trace("removing handler for channel " + fd);
- }
- }
-
- assert(!_destroyed);
- _changes.add(new FdHandlerPair(fd, null));
- setInterrupt(0);
- }
-
- public void
- promoteFollower()
- {
- if(_multipleThreads)
- {
- if(!_promote) // Double-checked locking.
- {
- synchronized(_promoteMonitor)
- {
- if(!_promote)
- {
- _promote = true;
- _promoteMonitor.notify();
- }
- }
- }
- }
- }
-
- public void
- initiateShutdown()
- {
- if(TRACE_SHUTDOWN)
- {
- trace("initiate server shutdown");
- }
-
- setInterrupt(1);
- }
-
- public void
- joinWithAllThreads()
- {
- //
- // _threads is immutable after the initial creation in the
- // constructor, therefore no synchronization is
- // needed. (Synchronization wouldn't be possible here anyway,
- // because otherwise the other threads would never terminate.)
- //
- for(int i = 0; i < _threads.length; i++)
- {
- while(true)
- {
- try
- {
- _threads[i].join();
- break;
- }
- catch(InterruptedException ex)
- {
- }
- }
- }
- }
-
- //
- // Only for use by Instance
- //
- ThreadPool(Instance instance, boolean server, String name)
+ public
+ ThreadPool(Instance instance, int threadNum, int timeout, String name)
{
_instance = instance;
_destroyed = false;
- _timeout = 0;
+ _timeout = timeout;
_multipleThreads = false;
_promote = true;
_name = name;
@@ -157,17 +57,6 @@ public final class ThreadPool
//
_keys = _selector.selectedKeys();
- int threadNum;
- if(server)
- {
- _timeout = _instance.properties().getPropertyAsInt("Ice.ServerIdleTime");
- threadNum = _instance.properties().getPropertyAsIntWithDefault("Ice.ThreadPool.Server.Size", 10);
- }
- else
- {
- threadNum = _instance.properties().getPropertyAsIntWithDefault("Ice.ThreadPool.Client.Size", 1);
- }
-
if(threadNum < 1)
{
threadNum = 1;
@@ -251,10 +140,7 @@ public final class ThreadPool
super.finalize();
}
- //
- // Called by Instance
- //
- synchronized void
+ public synchronized void
destroy()
{
if(TRACE_SHUTDOWN)
@@ -267,6 +153,104 @@ public final class ThreadPool
setInterrupt(0);
}
+ public synchronized void
+ _register(java.nio.channels.SelectableChannel fd, EventHandler handler)
+ {
+ if(TRACE_REGISTRATION)
+ {
+ trace("adding handler of type " + handler.getClass().getName() + " for channel " + fd);
+ }
+ assert(!_destroyed);
+ _changes.add(new FdHandlerPair(fd, handler));
+ setInterrupt(0);
+ }
+
+ public synchronized void
+ unregister(java.nio.channels.SelectableChannel fd)
+ {
+ if(TRACE_REGISTRATION)
+ {
+ if(TRACE_STACK_TRACE)
+ {
+ java.io.StringWriter sw = new java.io.StringWriter();
+ try
+ {
+ throw new RuntimeException();
+ }
+ catch(RuntimeException ex)
+ {
+ java.io.PrintWriter pw = new java.io.PrintWriter(sw);
+ ex.printStackTrace(pw);
+ pw.flush();
+ }
+ trace("removing handler for channel " + fd + "\n" + sw.toString());
+ }
+ else
+ {
+ trace("removing handler for channel " + fd);
+ }
+ }
+
+ assert(!_destroyed);
+ _changes.add(new FdHandlerPair(fd, null));
+ setInterrupt(0);
+ }
+
+ public void
+ promoteFollower()
+ {
+ if(_multipleThreads)
+ {
+ if(!_promote) // Double-checked locking.
+ {
+ synchronized(_promoteMonitor)
+ {
+ if(!_promote)
+ {
+ _promote = true;
+ _promoteMonitor.notify();
+ }
+ }
+ }
+ }
+ }
+
+ public void
+ initiateShutdown()
+ {
+ if(TRACE_SHUTDOWN)
+ {
+ trace("initiate server shutdown");
+ }
+
+ setInterrupt(1);
+ }
+
+ public void
+ joinWithAllThreads()
+ {
+ //
+ // _threads is immutable after the initial creation in the
+ // constructor, therefore no synchronization is
+ // needed. (Synchronization wouldn't be possible here anyway,
+ // because otherwise the other threads would never terminate.)
+ //
+ for(int i = 0; i < _threads.length; i++)
+ {
+ while(true)
+ {
+ try
+ {
+ _threads[i].join();
+ break;
+ }
+ catch(InterruptedException ex)
+ {
+ }
+ }
+ }
+ }
+
private boolean
clearInterrupt()
{