<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_by_API%2Fjava.lang%2FThreadGroup</id>
		<title>Java by API/java.lang/ThreadGroup - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_by_API%2Fjava.lang%2FThreadGroup"/>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_by_API/java.lang/ThreadGroup&amp;action=history"/>
		<updated>2026-04-10T09:01:24Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://jexp.ru/index.php?title=Java_by_API/java.lang/ThreadGroup&amp;diff=2044&amp;oldid=prev</id>
		<title> в 17:43, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_by_API/java.lang/ThreadGroup&amp;diff=2044&amp;oldid=prev"/>
				<updated>2010-05-31T17:43:48Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 17:43, 31 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://jexp.ru/index.php?title=Java_by_API/java.lang/ThreadGroup&amp;diff=2045&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_by_API/java.lang/ThreadGroup&amp;diff=2045&amp;oldid=prev"/>
				<updated>2010-05-31T14:40:25Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== new ThreadGroup(String groupName) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Output:&lt;br /&gt;
New thread: Thread[One,5,Group A]&lt;br /&gt;
New thread: Thread[Two,5,Group A]&lt;br /&gt;
One: 5&lt;br /&gt;
New thread: Thread[Three,5,Group B]&lt;br /&gt;
New thread: Thread[Four,5,Group B]&lt;br /&gt;
Here is output from list():&lt;br /&gt;
java.lang.ThreadGroup[name=Group A,maxpri=10]&lt;br /&gt;
    Thread[One,5,Group A]&lt;br /&gt;
    Thread[Two,5,Group A]&lt;br /&gt;
java.lang.ThreadGroup[name=Group B,maxpri=10]&lt;br /&gt;
    Thread[Three,5,Group B]&lt;br /&gt;
    Thread[Four,5,Group B]&lt;br /&gt;
Suspending Group A&lt;br /&gt;
Three: 5&lt;br /&gt;
Two: 5&lt;br /&gt;
Four: 5&lt;br /&gt;
Resuming Group A&lt;br /&gt;
Four: 4&lt;br /&gt;
Three: 4&lt;br /&gt;
Waiting for threads to finish.&lt;br /&gt;
Two: 4&lt;br /&gt;
 */&lt;br /&gt;
class MyThread extends Thread {&lt;br /&gt;
  boolean suspended;&lt;br /&gt;
  MyThread(String threadname, ThreadGroup tgOb) {&lt;br /&gt;
    super(tgOb, threadname);&lt;br /&gt;
    System.out.println(&amp;quot;New thread: &amp;quot; + this);&lt;br /&gt;
    suspended = false;&lt;br /&gt;
    start(); // Start the thread&lt;br /&gt;
  }&lt;br /&gt;
  public void run() {&lt;br /&gt;
    try {&lt;br /&gt;
      for (int i = 5; i &amp;gt; 0; i--) {&lt;br /&gt;
        System.out.println(getName() + &amp;quot;: &amp;quot; + i);&lt;br /&gt;
        Thread.sleep(1000);&lt;br /&gt;
        synchronized (this) {&lt;br /&gt;
          while (suspended) {&lt;br /&gt;
            wait();&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    } catch (Exception e) {&lt;br /&gt;
      System.out.println(&amp;quot;Exception in &amp;quot; + getName());&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(getName() + &amp;quot; exiting.&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  void suspendMe() {&lt;br /&gt;
    suspended = true;&lt;br /&gt;
  }&lt;br /&gt;
  synchronized void resumeMe() {&lt;br /&gt;
    suspended = false;&lt;br /&gt;
    notify();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    ThreadGroup groupA = new ThreadGroup(&amp;quot;Group A&amp;quot;);&lt;br /&gt;
    ThreadGroup groupB = new ThreadGroup(&amp;quot;Group B&amp;quot;);&lt;br /&gt;
    MyThread ob1 = new MyThread(&amp;quot;One&amp;quot;, groupA);&lt;br /&gt;
    MyThread ob2 = new MyThread(&amp;quot;Two&amp;quot;, groupA);&lt;br /&gt;
    MyThread ob3 = new MyThread(&amp;quot;Three&amp;quot;, groupB);&lt;br /&gt;
    MyThread ob4 = new MyThread(&amp;quot;Four&amp;quot;, groupB);&lt;br /&gt;
    System.out.println(&amp;quot;\nHere is output from list():&amp;quot;);&lt;br /&gt;
    groupA.list();&lt;br /&gt;
    groupB.list();&lt;br /&gt;
    System.out.println(&amp;quot;Suspending Group A&amp;quot;);&lt;br /&gt;
    Thread tga[] = new Thread[groupA.activeCount()];&lt;br /&gt;
    groupA.enumerate(tga); // get threads in group&lt;br /&gt;
    for (int i = 0; i &amp;lt; tga.length; i++) {&lt;br /&gt;
      ((MyThread) tga[i]).suspendMe(); // suspend each thread&lt;br /&gt;
    }&lt;br /&gt;
    try {&lt;br /&gt;
      Thread.sleep(1000);&lt;br /&gt;
    } catch (InterruptedException e) {&lt;br /&gt;
      System.out.println(&amp;quot;Main thread interrupted.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(&amp;quot;Resuming Group A&amp;quot;);&lt;br /&gt;
    for (int i = 0; i &amp;lt; tga.length; i++) {&lt;br /&gt;
      ((MyThread) tga[i]).resumeMe();&lt;br /&gt;
    }&lt;br /&gt;
    try {&lt;br /&gt;
      System.out.println(&amp;quot;Waiting for threads to finish.&amp;quot;);&lt;br /&gt;
      ob1.join();&lt;br /&gt;
      ob2.join();&lt;br /&gt;
      ob3.join();&lt;br /&gt;
      ob4.join();&lt;br /&gt;
    } catch (Exception e) {&lt;br /&gt;
      System.out.println(&amp;quot;Exception in Main thread&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(&amp;quot;Main thread exiting.&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ThreadGroup: activeCount() ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Output:&lt;br /&gt;
New thread: Thread[One,5,Group A]&lt;br /&gt;
New thread: Thread[Two,5,Group A]&lt;br /&gt;
One: 5&lt;br /&gt;
New thread: Thread[Three,5,Group B]&lt;br /&gt;
New thread: Thread[Four,5,Group B]&lt;br /&gt;
Here is output from list():&lt;br /&gt;
java.lang.ThreadGroup[name=Group A,maxpri=10]&lt;br /&gt;
    Thread[One,5,Group A]&lt;br /&gt;
    Thread[Two,5,Group A]&lt;br /&gt;
java.lang.ThreadGroup[name=Group B,maxpri=10]&lt;br /&gt;
    Thread[Three,5,Group B]&lt;br /&gt;
    Thread[Four,5,Group B]&lt;br /&gt;
Suspending Group A&lt;br /&gt;
Three: 5&lt;br /&gt;
Two: 5&lt;br /&gt;
Four: 5&lt;br /&gt;
Resuming Group A&lt;br /&gt;
Four: 4&lt;br /&gt;
Three: 4&lt;br /&gt;
Waiting for threads to finish.&lt;br /&gt;
Two: 4&lt;br /&gt;
 */&lt;br /&gt;
class MyThread extends Thread {&lt;br /&gt;
  boolean suspended;&lt;br /&gt;
  MyThread(String threadname, ThreadGroup tgOb) {&lt;br /&gt;
    super(tgOb, threadname);&lt;br /&gt;
    System.out.println(&amp;quot;New thread: &amp;quot; + this);&lt;br /&gt;
    suspended = false;&lt;br /&gt;
    start(); // Start the thread&lt;br /&gt;
  }&lt;br /&gt;
  public void run() {&lt;br /&gt;
    try {&lt;br /&gt;
      for (int i = 5; i &amp;gt; 0; i--) {&lt;br /&gt;
        System.out.println(getName() + &amp;quot;: &amp;quot; + i);&lt;br /&gt;
        Thread.sleep(1000);&lt;br /&gt;
        synchronized (this) {&lt;br /&gt;
          while (suspended) {&lt;br /&gt;
            wait();&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    } catch (Exception e) {&lt;br /&gt;
      System.out.println(&amp;quot;Exception in &amp;quot; + getName());&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(getName() + &amp;quot; exiting.&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  void suspendMe() {&lt;br /&gt;
    suspended = true;&lt;br /&gt;
  }&lt;br /&gt;
  synchronized void resumeMe() {&lt;br /&gt;
    suspended = false;&lt;br /&gt;
    notify();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    ThreadGroup groupA = new ThreadGroup(&amp;quot;Group A&amp;quot;);&lt;br /&gt;
    ThreadGroup groupB = new ThreadGroup(&amp;quot;Group B&amp;quot;);&lt;br /&gt;
    MyThread ob1 = new MyThread(&amp;quot;One&amp;quot;, groupA);&lt;br /&gt;
    MyThread ob2 = new MyThread(&amp;quot;Two&amp;quot;, groupA);&lt;br /&gt;
    MyThread ob3 = new MyThread(&amp;quot;Three&amp;quot;, groupB);&lt;br /&gt;
    MyThread ob4 = new MyThread(&amp;quot;Four&amp;quot;, groupB);&lt;br /&gt;
    System.out.println(&amp;quot;\nHere is output from list():&amp;quot;);&lt;br /&gt;
    groupA.list();&lt;br /&gt;
    groupB.list();&lt;br /&gt;
    System.out.println(&amp;quot;Suspending Group A&amp;quot;);&lt;br /&gt;
    Thread tga[] = new Thread[groupA.activeCount()];&lt;br /&gt;
    groupA.enumerate(tga); // get threads in group&lt;br /&gt;
    for (int i = 0; i &amp;lt; tga.length; i++) {&lt;br /&gt;
      ((MyThread) tga[i]).suspendMe(); // suspend each thread&lt;br /&gt;
    }&lt;br /&gt;
    try {&lt;br /&gt;
      Thread.sleep(1000);&lt;br /&gt;
    } catch (InterruptedException e) {&lt;br /&gt;
      System.out.println(&amp;quot;Main thread interrupted.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(&amp;quot;Resuming Group A&amp;quot;);&lt;br /&gt;
    for (int i = 0; i &amp;lt; tga.length; i++) {&lt;br /&gt;
      ((MyThread) tga[i]).resumeMe();&lt;br /&gt;
    }&lt;br /&gt;
    try {&lt;br /&gt;
      System.out.println(&amp;quot;Waiting for threads to finish.&amp;quot;);&lt;br /&gt;
      ob1.join();&lt;br /&gt;
      ob2.join();&lt;br /&gt;
      ob3.join();&lt;br /&gt;
      ob4.join();&lt;br /&gt;
    } catch (Exception e) {&lt;br /&gt;
      System.out.println(&amp;quot;Exception in Main thread&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(&amp;quot;Main thread exiting.&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ThreadGroup: activeGroupCount() ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
    ThreadGroup group = Thread.currentThread().getThreadGroup().getParent();&lt;br /&gt;
    while (group.getParent() != null) {&lt;br /&gt;
      group = group.getParent();&lt;br /&gt;
    }&lt;br /&gt;
    int numThreads = group.activeCount();&lt;br /&gt;
    Thread[] threads = new Thread[numThreads * 2];&lt;br /&gt;
    numThreads = group.enumerate(threads, false);&lt;br /&gt;
    for (int i = 0; i &amp;lt; numThreads; i++) {&lt;br /&gt;
      Thread thread = threads[i];&lt;br /&gt;
      System.out.println(thread.getName());&lt;br /&gt;
    }&lt;br /&gt;
    int numGroups = group.activeGroupCount();&lt;br /&gt;
    ThreadGroup[] groups = new ThreadGroup[numGroups * 2];&lt;br /&gt;
    numGroups = group.enumerate(groups, false);&lt;br /&gt;
    for (int i = 0; i &amp;lt; numGroups; i++) {&lt;br /&gt;
      System.out.println(groups[i]);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ThreadGroup: enumerate(Thread[] thread) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Output:&lt;br /&gt;
New thread: Thread[One,5,Group A]&lt;br /&gt;
New thread: Thread[Two,5,Group A]&lt;br /&gt;
One: 5&lt;br /&gt;
New thread: Thread[Three,5,Group B]&lt;br /&gt;
New thread: Thread[Four,5,Group B]&lt;br /&gt;
Here is output from list():&lt;br /&gt;
java.lang.ThreadGroup[name=Group A,maxpri=10]&lt;br /&gt;
    Thread[One,5,Group A]&lt;br /&gt;
    Thread[Two,5,Group A]&lt;br /&gt;
java.lang.ThreadGroup[name=Group B,maxpri=10]&lt;br /&gt;
    Thread[Three,5,Group B]&lt;br /&gt;
    Thread[Four,5,Group B]&lt;br /&gt;
Suspending Group A&lt;br /&gt;
Three: 5&lt;br /&gt;
Two: 5&lt;br /&gt;
Four: 5&lt;br /&gt;
Resuming Group A&lt;br /&gt;
Four: 4&lt;br /&gt;
Three: 4&lt;br /&gt;
Waiting for threads to finish.&lt;br /&gt;
Two: 4&lt;br /&gt;
 */&lt;br /&gt;
class MyThread extends Thread {&lt;br /&gt;
  boolean suspended;&lt;br /&gt;
  MyThread(String threadname, ThreadGroup tgOb) {&lt;br /&gt;
    super(tgOb, threadname);&lt;br /&gt;
    System.out.println(&amp;quot;New thread: &amp;quot; + this);&lt;br /&gt;
    suspended = false;&lt;br /&gt;
    start(); // Start the thread&lt;br /&gt;
  }&lt;br /&gt;
  public void run() {&lt;br /&gt;
    try {&lt;br /&gt;
      for (int i = 5; i &amp;gt; 0; i--) {&lt;br /&gt;
        System.out.println(getName() + &amp;quot;: &amp;quot; + i);&lt;br /&gt;
        Thread.sleep(1000);&lt;br /&gt;
        synchronized (this) {&lt;br /&gt;
          while (suspended) {&lt;br /&gt;
            wait();&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    } catch (Exception e) {&lt;br /&gt;
      System.out.println(&amp;quot;Exception in &amp;quot; + getName());&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(getName() + &amp;quot; exiting.&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  void suspendMe() {&lt;br /&gt;
    suspended = true;&lt;br /&gt;
  }&lt;br /&gt;
  synchronized void resumeMe() {&lt;br /&gt;
    suspended = false;&lt;br /&gt;
    notify();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    ThreadGroup groupA = new ThreadGroup(&amp;quot;Group A&amp;quot;);&lt;br /&gt;
    ThreadGroup groupB = new ThreadGroup(&amp;quot;Group B&amp;quot;);&lt;br /&gt;
    MyThread ob1 = new MyThread(&amp;quot;One&amp;quot;, groupA);&lt;br /&gt;
    MyThread ob2 = new MyThread(&amp;quot;Two&amp;quot;, groupA);&lt;br /&gt;
    MyThread ob3 = new MyThread(&amp;quot;Three&amp;quot;, groupB);&lt;br /&gt;
    MyThread ob4 = new MyThread(&amp;quot;Four&amp;quot;, groupB);&lt;br /&gt;
    System.out.println(&amp;quot;\nHere is output from list():&amp;quot;);&lt;br /&gt;
    groupA.list();&lt;br /&gt;
    groupB.list();&lt;br /&gt;
    System.out.println(&amp;quot;Suspending Group A&amp;quot;);&lt;br /&gt;
    Thread tga[] = new Thread[groupA.activeCount()];&lt;br /&gt;
    groupA.enumerate(tga); // get threads in group&lt;br /&gt;
    for (int i = 0; i &amp;lt; tga.length; i++) {&lt;br /&gt;
      ((MyThread) tga[i]).suspendMe(); // suspend each thread&lt;br /&gt;
    }&lt;br /&gt;
    try {&lt;br /&gt;
      Thread.sleep(1000);&lt;br /&gt;
    } catch (InterruptedException e) {&lt;br /&gt;
      System.out.println(&amp;quot;Main thread interrupted.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(&amp;quot;Resuming Group A&amp;quot;);&lt;br /&gt;
    for (int i = 0; i &amp;lt; tga.length; i++) {&lt;br /&gt;
      ((MyThread) tga[i]).resumeMe();&lt;br /&gt;
    }&lt;br /&gt;
    try {&lt;br /&gt;
      System.out.println(&amp;quot;Waiting for threads to finish.&amp;quot;);&lt;br /&gt;
      ob1.join();&lt;br /&gt;
      ob2.join();&lt;br /&gt;
      ob3.join();&lt;br /&gt;
      ob4.join();&lt;br /&gt;
    } catch (Exception e) {&lt;br /&gt;
      System.out.println(&amp;quot;Exception in Main thread&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(&amp;quot;Main thread exiting.&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ThreadGroup: getName() ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    ThreadGroup tg = new ThreadGroup(&amp;quot;My ThreadGroup&amp;quot;);&lt;br /&gt;
    MyThread mt = new MyThread(tg, &amp;quot;My Thread&amp;quot;);&lt;br /&gt;
    mt.start();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class MyThread extends Thread {&lt;br /&gt;
  MyThread(ThreadGroup tg, String name) {&lt;br /&gt;
    super(tg, name);&lt;br /&gt;
  }&lt;br /&gt;
  public void run() {&lt;br /&gt;
    ThreadGroup tg = getThreadGroup();&lt;br /&gt;
    System.out.println(tg.getName());&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ThreadGroup: getParent() ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
    ThreadGroup group = Thread.currentThread().getThreadGroup().getParent();&lt;br /&gt;
    while (group.getParent() != null) {&lt;br /&gt;
      group = group.getParent();&lt;br /&gt;
    }&lt;br /&gt;
    int numThreads = group.activeCount();&lt;br /&gt;
    Thread[] threads = new Thread[numThreads * 2];&lt;br /&gt;
    numThreads = group.enumerate(threads, false);&lt;br /&gt;
    for (int i = 0; i &amp;lt; numThreads; i++) {&lt;br /&gt;
      Thread thread = threads[i];&lt;br /&gt;
      System.out.println(thread.getName());&lt;br /&gt;
    }&lt;br /&gt;
    int numGroups = group.activeGroupCount();&lt;br /&gt;
    ThreadGroup[] groups = new ThreadGroup[numGroups * 2];&lt;br /&gt;
    numGroups = group.enumerate(groups, false);&lt;br /&gt;
    for (int i = 0; i &amp;lt; numGroups; i++) {&lt;br /&gt;
      System.out.println(groups[i]);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ThreadGroup: list() ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Output:&lt;br /&gt;
New thread: Thread[One,5,Group A]&lt;br /&gt;
New thread: Thread[Two,5,Group A]&lt;br /&gt;
One: 5&lt;br /&gt;
New thread: Thread[Three,5,Group B]&lt;br /&gt;
New thread: Thread[Four,5,Group B]&lt;br /&gt;
Here is output from list():&lt;br /&gt;
java.lang.ThreadGroup[name=Group A,maxpri=10]&lt;br /&gt;
    Thread[One,5,Group A]&lt;br /&gt;
    Thread[Two,5,Group A]&lt;br /&gt;
java.lang.ThreadGroup[name=Group B,maxpri=10]&lt;br /&gt;
    Thread[Three,5,Group B]&lt;br /&gt;
    Thread[Four,5,Group B]&lt;br /&gt;
Suspending Group A&lt;br /&gt;
Three: 5&lt;br /&gt;
Two: 5&lt;br /&gt;
Four: 5&lt;br /&gt;
Resuming Group A&lt;br /&gt;
Four: 4&lt;br /&gt;
Three: 4&lt;br /&gt;
Waiting for threads to finish.&lt;br /&gt;
Two: 4&lt;br /&gt;
 */&lt;br /&gt;
class MyThread extends Thread {&lt;br /&gt;
  boolean suspended;&lt;br /&gt;
  MyThread(String threadname, ThreadGroup tgOb) {&lt;br /&gt;
    super(tgOb, threadname);&lt;br /&gt;
    System.out.println(&amp;quot;New thread: &amp;quot; + this);&lt;br /&gt;
    suspended = false;&lt;br /&gt;
    start(); // Start the thread&lt;br /&gt;
  }&lt;br /&gt;
  public void run() {&lt;br /&gt;
    try {&lt;br /&gt;
      for (int i = 5; i &amp;gt; 0; i--) {&lt;br /&gt;
        System.out.println(getName() + &amp;quot;: &amp;quot; + i);&lt;br /&gt;
        Thread.sleep(1000);&lt;br /&gt;
        synchronized (this) {&lt;br /&gt;
          while (suspended) {&lt;br /&gt;
            wait();&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    } catch (Exception e) {&lt;br /&gt;
      System.out.println(&amp;quot;Exception in &amp;quot; + getName());&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(getName() + &amp;quot; exiting.&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  void suspendMe() {&lt;br /&gt;
    suspended = true;&lt;br /&gt;
  }&lt;br /&gt;
  synchronized void resumeMe() {&lt;br /&gt;
    suspended = false;&lt;br /&gt;
    notify();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    ThreadGroup groupA = new ThreadGroup(&amp;quot;Group A&amp;quot;);&lt;br /&gt;
    ThreadGroup groupB = new ThreadGroup(&amp;quot;Group B&amp;quot;);&lt;br /&gt;
    MyThread ob1 = new MyThread(&amp;quot;One&amp;quot;, groupA);&lt;br /&gt;
    MyThread ob2 = new MyThread(&amp;quot;Two&amp;quot;, groupA);&lt;br /&gt;
    MyThread ob3 = new MyThread(&amp;quot;Three&amp;quot;, groupB);&lt;br /&gt;
    MyThread ob4 = new MyThread(&amp;quot;Four&amp;quot;, groupB);&lt;br /&gt;
    System.out.println(&amp;quot;\nHere is output from list():&amp;quot;);&lt;br /&gt;
    groupA.list();&lt;br /&gt;
    groupB.list();&lt;br /&gt;
    System.out.println(&amp;quot;Suspending Group A&amp;quot;);&lt;br /&gt;
    Thread tga[] = new Thread[groupA.activeCount()];&lt;br /&gt;
    groupA.enumerate(tga); // get threads in group&lt;br /&gt;
    for (int i = 0; i &amp;lt; tga.length; i++) {&lt;br /&gt;
      ((MyThread) tga[i]).suspendMe(); // suspend each thread&lt;br /&gt;
    }&lt;br /&gt;
    try {&lt;br /&gt;
      Thread.sleep(1000);&lt;br /&gt;
    } catch (InterruptedException e) {&lt;br /&gt;
      System.out.println(&amp;quot;Main thread interrupted.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(&amp;quot;Resuming Group A&amp;quot;);&lt;br /&gt;
    for (int i = 0; i &amp;lt; tga.length; i++) {&lt;br /&gt;
      ((MyThread) tga[i]).resumeMe();&lt;br /&gt;
    }&lt;br /&gt;
    try {&lt;br /&gt;
      System.out.println(&amp;quot;Waiting for threads to finish.&amp;quot;);&lt;br /&gt;
      ob1.join();&lt;br /&gt;
      ob2.join();&lt;br /&gt;
      ob3.join();&lt;br /&gt;
      ob4.join();&lt;br /&gt;
    } catch (Exception e) {&lt;br /&gt;
      System.out.println(&amp;quot;Exception in Main thread&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(&amp;quot;Main thread exiting.&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>