From 244bab6ebcc315a044ab843b216869ef68ac87bb Mon Sep 17 00:00:00 2001 From: Stephan Herrmann Date: Sun, 27 Jun 2010 11:07:49 +0000 Subject: Fixes for Bug 316696 - [otre] OTRE doesn't know about all threads (see comment 2) also includes deployment issues. --- othersrc/OTRE/src/org/objectteams/Team.java | 6 ----- .../src/org/objectteams/TeamThreadManager.java | 28 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 8 deletions(-) (limited to 'othersrc') diff --git a/othersrc/OTRE/src/org/objectteams/Team.java b/othersrc/OTRE/src/org/objectteams/Team.java index fe0a5145a..5feaccacf 100644 --- a/othersrc/OTRE/src/org/objectteams/Team.java +++ b/othersrc/OTRE/src/org/objectteams/Team.java @@ -16,7 +16,6 @@ **********************************************************************/ package org.objectteams; -import java.awt.EventQueue; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -174,9 +173,6 @@ public /* team */ class Team implements ITeam { synchronized (this._OT$registrationLock) { boolean shouldUnregister= false; synchronized(this) { - if (_OT$globalActive && EventQueue.isDispatchThread()) { - System.err.println("Warning: Deactivation for the AWT-Event-Thread is not effective right now!"); - } if (thread.equals(ALL_THREADS)) { _OT$globalActive = false; TeamThreadManager.removeGlobalActiveTeam(this); @@ -313,8 +309,6 @@ public /* team */ class Team implements ITeam { * {@inheritDoc} */ public boolean isActive(Thread thread) { - if (_OT$globalActive && EventQueue.isDispatchThread()) - return true; if (thread.equals(ALL_THREADS)) { return _OT$globalActive; } diff --git a/othersrc/OTRE/src/org/objectteams/TeamThreadManager.java b/othersrc/OTRE/src/org/objectteams/TeamThreadManager.java index ce1b174a6..debccb712 100644 --- a/othersrc/OTRE/src/org/objectteams/TeamThreadManager.java +++ b/othersrc/OTRE/src/org/objectteams/TeamThreadManager.java @@ -38,10 +38,11 @@ public class TeamThreadManager { private static HashSet existingThreads = new HashSet(); public static boolean newThreadStarted(boolean isMain, Thread parent) { - if (!isMain && (new Exception().getStackTrace().length > 3)) + Thread currentThread = Thread.currentThread(); + // already registered? + if (existingThreads.contains(currentThread)) return false; // workaround for application hang on Mac OS with Apple JVM: - Thread currentThread = Thread.currentThread(); if (System.getProperty("os.name").startsWith("Mac")) if (currentThread.getName().equals("AWT-Shutdown")) return false; @@ -50,6 +51,11 @@ public class TeamThreadManager { ITeam[] inheritableTeams; synchronized (TeamThreadManager.class) { existingThreads.add(currentThread); + if (isMain) { + for (Thread thread : fetchSystemThreads(currentThread)) + if (thread != null) + existingThreads.add(thread); + } globalTeams = globalActiveTeams.toArray(new ITeam[globalActiveTeams.size()]); inheritableTeams = teamsWithActivationInheritance.keySet().toArray(new ITeam[teamsWithActivationInheritance.size()]); @@ -63,6 +69,24 @@ public class TeamThreadManager { t.activate(currentThread); // pass activation from parent to child thread return true; } + + /* Fetch all existing threads existing at this point in time. Result array is padded with nulls. */ + private static Thread[] fetchSystemThreads(Thread currentThread) { + ThreadGroup group = currentThread.getThreadGroup(); + { + ThreadGroup parentGroup; + while ((parentGroup= group.getParent()) != null) + group = parentGroup; + } + int size = group.activeCount(); + Thread[] allThreads; + do { + size += 2; + allThreads = new Thread[size]; + } while (group.enumerate(allThreads) == size); + return allThreads; + } + public static void threadEnded() { ITeam[] teamsToDeactivate = internalThreadEnded(); // + remove per thread activation: -- cgit v1.2.3