summaryrefslogtreecommitdiff
path: root/java/JACE/Concurrency/ThreadManager.java
diff options
context:
space:
mode:
authoreea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-08-24 23:10:15 +0000
committereea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-08-24 23:10:15 +0000
commite4012b2dc8297540c9501a10daa8b8746d55297e (patch)
treeef60f5324a9022443eb683594e2d415ea46d08eb /java/JACE/Concurrency/ThreadManager.java
parentf69420de3b964a4f1de9b9c310ca9ced2461e24e (diff)
downloadATCD-e4012b2dc8297540c9501a10daa8b8746d55297e.tar.gz
Updated source files for Concurrency.
Diffstat (limited to 'java/JACE/Concurrency/ThreadManager.java')
-rw-r--r--java/JACE/Concurrency/ThreadManager.java113
1 files changed, 113 insertions, 0 deletions
diff --git a/java/JACE/Concurrency/ThreadManager.java b/java/JACE/Concurrency/ThreadManager.java
new file mode 100644
index 00000000000..d23e2410676
--- /dev/null
+++ b/java/JACE/Concurrency/ThreadManager.java
@@ -0,0 +1,113 @@
+/*************************************************
+ *
+ * = PACKAGE
+ * JACE.Concurrency
+ *
+ * = FILENAME
+ * ThreadManager.java
+ *
+ *@author Prashant Jain
+ *
+ *************************************************/
+package JACE.Concurrency;
+
+import java.util.*;
+import JACE.OS.*;
+
+/**
+ * Wrapper for a ThreadGroup which provides additional methods for
+ * creating a certain number of Runnable instances.
+ */
+public class ThreadManager
+{
+ /**
+ * Default constructor
+ */
+ public ThreadManager ()
+ {
+ this (ACE.DEFAULT_THREAD_GROUP_NAME);
+ }
+
+ /**
+ * Create a Thread Manager.
+ *@param groupName name of the thread group that the Thread Manager
+ * will manage
+ */
+ public ThreadManager (String groupName)
+ {
+ this.thrGrp_ = new ThreadGroup (groupName);
+ if (this.thrGrp_ == null)
+ ACE.ERROR ("Thread group create failed");
+ }
+
+ /**
+ * Create a new thread.
+ *@param thr the caller whose run method will be invoked when the
+ * thread has been spawned
+ *@param daemon flag indicating whether the thread should be
+ * spawned off as a daemon thread
+ */
+ public void spawn (Runnable thr,
+ boolean daemon)
+ {
+ Thread t = new Thread (this.thrGrp_, thr);
+ if (daemon) // Set the thread to be a daemon thread
+ t.setDaemon (true);
+ t.start ();
+ }
+
+ /**
+ * Create a new thread and also give it a name.
+ *@param thr the caller whose run method will be invoked when the
+ * thread has been spawned
+ *@param threadName the name of the new thread
+ *@param daemon flag indicating whether the thread should be
+ * spawned off as a daemon thread
+ */
+ public void spawn (Runnable thr,
+ String threadName,
+ boolean daemon)
+ {
+ Thread t = new Thread (this.thrGrp_, thr, threadName);
+ if (daemon) // Set the thread to be a daemon thread
+ t.setDaemon (true);
+ t.start ();
+ }
+
+
+ /**
+ * Create <n> new threads.
+ *@param n the number of threads to spawn
+ *@param thr the caller whose run method will be invoked by each of
+ * the <n> threads
+ *@param daemon flag indicating whether the threads should be
+ * spawned off as daemon threads
+ */
+ public void spawnN (int n,
+ Runnable thr,
+ boolean daemon)
+ {
+ // Spawn off all the threads.
+ for (int i = 0; i < n; i++)
+ {
+ this.spawn (thr, daemon);
+ }
+ }
+
+ /**
+ * Get the thread group containing all the threads. Note that the
+ * thread group can be used to get information regarding number of
+ * active threads as well as to suspend/resume all the threads in
+ * the group.
+ *@return the thread group that contains all the threads managed by
+ * the Thread Manager
+ */
+ public ThreadGroup thrGrp ()
+ {
+ return this.thrGrp_;
+ }
+
+ private ThreadGroup thrGrp_;
+ // Thread Group that contains all the spawned threads
+
+}