summaryrefslogtreecommitdiff
path: root/java/src/IceInternal/ThreadPool.java
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2009-05-01 13:59:45 -0230
committerDwayne Boone <dwayne@zeroc.com>2009-05-01 13:59:45 -0230
commite2759d2abadc5764c4ff6939439f6018c46edc92 (patch)
treee996efb07ca08ffef7a4d9255c56ddef6d8e0c46 /java/src/IceInternal/ThreadPool.java
parentBug 3972 - improve server network tracing (diff)
downloadice-e2759d2abadc5764c4ff6939439f6018c46edc92.tar.bz2
ice-e2759d2abadc5764c4ff6939439f6018c46edc92.tar.xz
ice-e2759d2abadc5764c4ff6939439f6018c46edc92.zip
Bug 994 - use StackSize for Java and C#
Diffstat (limited to 'java/src/IceInternal/ThreadPool.java')
-rw-r--r--java/src/IceInternal/ThreadPool.java72
1 files changed, 53 insertions, 19 deletions
diff --git a/java/src/IceInternal/ThreadPool.java b/java/src/IceInternal/ThreadPool.java
index 6b6551806ad..f897b20fefe 100644
--- a/java/src/IceInternal/ThreadPool.java
+++ b/java/src/IceInternal/ThreadPool.java
@@ -85,6 +85,16 @@ public final class ThreadPool
_sizeMax = sizeMax;
_sizeWarn = sizeWarn;
+ int stackSize = _instance.initializationData().properties.getPropertyAsInt( _prefix + ".StackSize");
+ if(stackSize < 0)
+ {
+ String s = _prefix + ".StackSize < 0; Size adjusted to JRE default";
+ _instance.initializationData().logger.warning(s);
+ stackSize = 0;
+ }
+
+ _stackSize = stackSize;
+
if(_instance.traceLevels().threadPool >= 1)
{
String s = "creating " + _prefix + ": Size = " + _size + ", SizeMax = " + _sizeMax + ", SizeWarn = " +
@@ -287,17 +297,7 @@ public final class ThreadPool
//
for(EventHandlerThread thread : _threads)
{
- while(true)
- {
- try
- {
- thread.join();
- break;
- }
- catch(InterruptedException ex)
- {
- }
- }
+ thread.join(true);
}
//
@@ -649,14 +649,10 @@ public final class ThreadPool
if(!thread.isAlive())
{
- try
+ if(thread.join(false))
{
- thread.join();
i.remove();
}
- catch(InterruptedException ex)
- {
- }
}
}
}
@@ -967,11 +963,44 @@ public final class ThreadPool
private java.util.LinkedList<EventHandler> _finished = new java.util.LinkedList<EventHandler>();
private int _timeout;
- private final class EventHandlerThread extends Thread
+ private final class EventHandlerThread implements Runnable
{
EventHandlerThread(String name)
{
- super(name);
+ _name = name;
+ }
+
+ public boolean
+ isAlive()
+ {
+ return _thread.isAlive();
+ }
+
+ public boolean
+ join(boolean wait)
+ {
+ while(true)
+ {
+ try
+ {
+ _thread.join();
+ return true;
+ }
+ catch(InterruptedException ex)
+ {
+ if(!wait)
+ {
+ return false;
+ }
+ }
+ }
+ }
+
+ public void
+ start()
+ {
+ _thread = new Thread(null, this, _name, _stackSize);
+ _thread.start();
}
public void
@@ -996,7 +1025,7 @@ public final class ThreadPool
java.io.PrintWriter pw = new java.io.PrintWriter(sw);
ex.printStackTrace(pw);
pw.flush();
- String s = "exception in `" + _prefix + "' thread " + getName() + ":\n" + sw.toString();
+ String s = "exception in `" + _prefix + "' thread " + _name + ":\n" + sw.toString();
_instance.initializationData().logger.error(s);
promote = true;
}
@@ -1025,6 +1054,9 @@ public final class ThreadPool
_instance.initializationData().threadHook.stop();
}
}
+
+ private String _name;
+ private Thread _thread;
}
private final int _size; // Number of threads that are pre-created.
@@ -1032,6 +1064,8 @@ public final class ThreadPool
private final int _sizeWarn; // If _inUse reaches _sizeWarn, a "low on threads" warning will be printed.
private final boolean _serialize; // True if requests need to be serialized over the connection.
+ private final int _stackSize;
+
private java.util.List<EventHandlerThread> _threads; // All threads, running or not.
private int _threadIndex; // For assigning thread names.
private int _running; // Number of running threads.