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

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Thread/ThreadGroup&amp;diff=2761&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Thread/ThreadGroup&amp;diff=2761&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:26Z</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:44, 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://www.jexp.ru/index.php?title=Java_Tutorial/Thread/ThreadGroup&amp;diff=2762&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Thread/ThreadGroup&amp;diff=2762&amp;oldid=prev"/>
				<updated>2010-05-31T15:18:01Z</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;==  Add thread to thread group ==&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;
class ThreadGroupDemo1 {&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;
}&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;
==  Demonstrate thread groups. ==&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;
class NewThread extends Thread {&lt;br /&gt;
  boolean suspendFlag;&lt;br /&gt;
  NewThread(String threadname, ThreadGroup tgOb) {&lt;br /&gt;
    super(tgOb, threadname);&lt;br /&gt;
    suspendFlag = false;&lt;br /&gt;
    start();&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 (suspendFlag) {&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;
  }&lt;br /&gt;
  void mysuspend() {&lt;br /&gt;
    suspendFlag = true;&lt;br /&gt;
  }&lt;br /&gt;
  synchronized void myresume() {&lt;br /&gt;
    suspendFlag = false;&lt;br /&gt;
    notify();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class ThreadGroupDemo {&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;
    NewThread ob1 = new NewThread(&amp;quot;One&amp;quot;, groupA);&lt;br /&gt;
    NewThread ob2 = new NewThread(&amp;quot;Two&amp;quot;, groupA);&lt;br /&gt;
    NewThread ob3 = new NewThread(&amp;quot;Three&amp;quot;, groupB);&lt;br /&gt;
    NewThread ob4 = new NewThread(&amp;quot;Four&amp;quot;, groupB);&lt;br /&gt;
    groupA.list();&lt;br /&gt;
    groupB.list();&lt;br /&gt;
    Thread tga[] = new Thread[groupA.activeCount()];&lt;br /&gt;
    groupA.enumerate(tga); &lt;br /&gt;
    for (int i = 0; i &amp;lt; tga.length; i++) {&lt;br /&gt;
      ((NewThread) tga[i]).mysuspend(); &lt;br /&gt;
    }&lt;br /&gt;
    try {&lt;br /&gt;
      Thread.sleep(4000);&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;
      ((NewThread) tga[i]).myresume(); &lt;br /&gt;
    }&lt;br /&gt;
    try {&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;
  }&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;
==  Get parent thread group ==&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;
class Main {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    ThreadGroup tg = Thread.currentThread().getThreadGroup();&lt;br /&gt;
    MyThread mt1 = new MyThread(tg, &amp;quot;first&amp;quot;);&lt;br /&gt;
    MyThread mt2 = new MyThread(tg, &amp;quot;second&amp;quot;);&lt;br /&gt;
    mt1.start();&lt;br /&gt;
    mt2.start();&lt;br /&gt;
    ThreadGroup parent = tg.getParent();&lt;br /&gt;
    Thread[] list = new Thread[parent.activeCount()];&lt;br /&gt;
    int count = parent.enumerate(list, true);&lt;br /&gt;
    String[] thdinfo = new String[count];&lt;br /&gt;
    for (int i = 0; i &amp;lt; count; i++)&lt;br /&gt;
      thdinfo[i] = list[i].toString();&lt;br /&gt;
    mt1.join();&lt;br /&gt;
    mt2.join();&lt;br /&gt;
    for (int i = 0; i &amp;lt; count; i++)&lt;br /&gt;
      System.out.println(thdinfo[i]);&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;
    for (char c = &amp;quot;A&amp;quot;; c &amp;lt;= &amp;quot;Z&amp;quot;; c++)&lt;br /&gt;
      System.out.println(c);&lt;br /&gt;
    try {&lt;br /&gt;
      Thread.sleep(1000);&lt;br /&gt;
    } catch (InterruptedException e) {&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;
==  Listing all threads and threadgroups in the VM ==&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;
 * Copyright (c) 2004 David Flanagan.  All rights reserved.&lt;br /&gt;
 * This code is from the book Java Examples in a Nutshell, 3nd Edition.&lt;br /&gt;
 * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied.&lt;br /&gt;
 * You may study, use, and modify it for any non-commercial purpose,&lt;br /&gt;
 * including teaching and use in open-source projects.&lt;br /&gt;
 * You may distribute it non-commercially as long as you retain this notice.&lt;br /&gt;
 * For a commercial use license, or to purchase the book, &lt;br /&gt;
 * please visit http://www.davidflanagan.ru/javaexamples3.&lt;br /&gt;
 */&lt;br /&gt;
import java.awt.BorderLayout;&lt;br /&gt;
import java.io.PrintWriter;&lt;br /&gt;
import java.io.StringWriter;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
import javax.swing.JScrollPane;&lt;br /&gt;
import javax.swing.JTextArea;&lt;br /&gt;
/**&lt;br /&gt;
 * This class contains a useful static method for listing all threads and&lt;br /&gt;
 * threadgroups in the VM. It also has a simple main() method so it can be run&lt;br /&gt;
 * as a standalone program.&lt;br /&gt;
 */&lt;br /&gt;
public class ThreadLister {&lt;br /&gt;
  /** Display information about a thread. */&lt;br /&gt;
  private static void printThreadInfo(PrintWriter out, Thread t, String indent) {&lt;br /&gt;
    if (t == null)&lt;br /&gt;
      return;&lt;br /&gt;
    out.println(indent + &amp;quot;Thread: &amp;quot; + t.getName() + &amp;quot;  Priority: &amp;quot; + t.getPriority()&lt;br /&gt;
        + (t.isDaemon() ? &amp;quot; Daemon&amp;quot; : &amp;quot;&amp;quot;) + (t.isAlive() ? &amp;quot;&amp;quot; : &amp;quot; Not Alive&amp;quot;));&lt;br /&gt;
  }&lt;br /&gt;
  /** Display info about a thread group and its threads and groups */&lt;br /&gt;
  private static void printGroupInfo(PrintWriter out, ThreadGroup g, String indent) {&lt;br /&gt;
    if (g == null)&lt;br /&gt;
      return;&lt;br /&gt;
    int num_threads = g.activeCount();&lt;br /&gt;
    int num_groups = g.activeGroupCount();&lt;br /&gt;
    Thread[] threads = new Thread[num_threads];&lt;br /&gt;
    ThreadGroup[] groups = new ThreadGroup[num_groups];&lt;br /&gt;
    g.enumerate(threads, false);&lt;br /&gt;
    g.enumerate(groups, false);&lt;br /&gt;
    out.println(indent + &amp;quot;Thread Group: &amp;quot; + g.getName() + &amp;quot;  Max Priority: &amp;quot; + g.getMaxPriority()&lt;br /&gt;
        + (g.isDaemon() ? &amp;quot; Daemon&amp;quot; : &amp;quot;&amp;quot;));&lt;br /&gt;
    for (int i = 0; i &amp;lt; num_threads; i++)&lt;br /&gt;
      printThreadInfo(out, threads[i], indent + &amp;quot;    &amp;quot;);&lt;br /&gt;
    for (int i = 0; i &amp;lt; num_groups; i++)&lt;br /&gt;
      printGroupInfo(out, groups[i], indent + &amp;quot;    &amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  /** Find the root thread group and list it recursively */&lt;br /&gt;
  public static void listAllThreads(PrintWriter out) {&lt;br /&gt;
    ThreadGroup current_thread_group;&lt;br /&gt;
    ThreadGroup root_thread_group;&lt;br /&gt;
    ThreadGroup parent;&lt;br /&gt;
    // Get the current thread group&lt;br /&gt;
    current_thread_group = Thread.currentThread().getThreadGroup();&lt;br /&gt;
    // Now go find the root thread group&lt;br /&gt;
    root_thread_group = current_thread_group;&lt;br /&gt;
    parent = root_thread_group.getParent();&lt;br /&gt;
    while (parent != null) {&lt;br /&gt;
      root_thread_group = parent;&lt;br /&gt;
      parent = parent.getParent();&lt;br /&gt;
    }&lt;br /&gt;
    // And list it, recursively&lt;br /&gt;
    printGroupInfo(out, root_thread_group, &amp;quot;&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * The main() method create a simple graphical user interface to display the&lt;br /&gt;
   * threads in. This allows us to see the &amp;quot;event dispatch thread&amp;quot; used by AWT&lt;br /&gt;
   * and Swing.&lt;br /&gt;
   */&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    // Create a simple Swing GUI&lt;br /&gt;
    JFrame frame = new JFrame(&amp;quot;ThreadLister Demo&amp;quot;);&lt;br /&gt;
    JTextArea textarea = new JTextArea();&lt;br /&gt;
    frame.getContentPane().add(new JScrollPane(textarea), BorderLayout.CENTER);&lt;br /&gt;
    frame.setSize(500, 400);&lt;br /&gt;
    frame.setVisible(true);&lt;br /&gt;
    // Get the threadlisting as a string using a StringWriter stream&lt;br /&gt;
    StringWriter sout = new StringWriter(); // To capture the listing&lt;br /&gt;
    PrintWriter out = new PrintWriter(sout);&lt;br /&gt;
    ThreadLister.listAllThreads(out); // List threads to stream&lt;br /&gt;
    out.close();&lt;br /&gt;
    String threadListing = sout.toString(); // Get listing as a string&lt;br /&gt;
    // Finally, display the thread listing in the GUI&lt;br /&gt;
    textarea.setText(threadListing);&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>