Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-09-27 07:48:24 +0000
committerEike Stepper2008-09-27 07:48:24 +0000
commitd0f8a39011921f62e4f02a4e7ceba0da34d4988b (patch)
tree82f189232d69113b75eec8ff10963d6a18e8710f /plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/MonitoredThread.java
parentf91aa6bd0c81ea9b585ebf09cae8d0470cfced09 (diff)
downloadcdo-d0f8a39011921f62e4f02a4e7ceba0da34d4988b.tar.gz
cdo-d0f8a39011921f62e4f02a4e7ceba0da34d4988b.tar.xz
cdo-d0f8a39011921f62e4f02a4e7ceba0da34d4988b.zip
test
Diffstat (limited to 'plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/MonitoredThread.java')
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/MonitoredThread.java66
1 files changed, 46 insertions, 20 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/MonitoredThread.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/MonitoredThread.java
index 0e60179ddf..f12b176ad1 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/MonitoredThread.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/MonitoredThread.java
@@ -43,6 +43,17 @@ public abstract class MonitoredThread extends Thread
return timeStamp;
}
+ public boolean isIdleTimeoutExpired(long idleTimeOut)
+ {
+ if (timeStamp != 0L) // Skip in first loop
+ {
+ long idle = System.currentTimeMillis() - timeStamp;
+ return idle > idleTimeOut;
+ }
+
+ return false;
+ }
+
public void heartBeat()
{
if (shutdown)
@@ -190,18 +201,11 @@ public abstract class MonitoredThread extends Thread
public void run()
{
- for (MonitoredThread thread : threads)
- {
- thread.start();
- }
-
- if (startLatch != null)
- {
- startLatch.countDown();
- }
+ startupThreads();
for (;;)
{
+ List<MonitoredThread> idleThreads = new ArrayList<MonitoredThread>();
synchronized (threads)
{
if (threads.isEmpty())
@@ -209,26 +213,50 @@ public abstract class MonitoredThread extends Thread
break;
}
- long now = System.currentTimeMillis();
for (MonitoredThread thread : threads)
{
- long timeStamp = thread.getTimeStamp();
- if (timeStamp != 0L) // Skip in first loop
+ if (thread.isIdleTimeoutExpired(idleTimeOut))
{
- long idle = now - timeStamp;
- if (idle > idleTimeOut)
- {
- handleTimeoutExpiration(thread, idle);
- }
+ idleThreads.add(thread);
}
}
}
+
+ for (MonitoredThread thread : idleThreads)
+ {
+ synchronized (threads)
+ {
+ threads.remove(thread);
+ }
+
+ handleTimeoutExpiration(thread);
+ }
}
ConcurrencyUtil.sleep(10);
}
- protected void handleTimeoutExpiration(MonitoredThread thread, long idle)
+ protected void handleTimeoutExpiration(MonitoredThread thread)
+ {
+ shutdownThreads();
+
+ throw new RuntimeException("Idle timeout expired: " + thread.getName());
+ }
+
+ private void startupThreads()
+ {
+ for (MonitoredThread thread : threads)
+ {
+ thread.start();
+ }
+
+ if (startLatch != null)
+ {
+ startLatch.countDown();
+ }
+ }
+
+ private void shutdownThreads()
{
synchronized (threads)
{
@@ -237,8 +265,6 @@ public abstract class MonitoredThread extends Thread
t.shutdown();
}
}
-
- throw new RuntimeException(thread.getName() + " idle timeout expired: " + idle);
}
}
}

Back to the top