<?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%2FThread_Join</id>
		<title>Java Tutorial/Thread/Thread Join - История изменений</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%2FThread_Join"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Thread/Thread_Join&amp;action=history"/>
		<updated>2026-04-21T22:31:11Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Thread/Thread_Join&amp;diff=2765&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/Thread_Join&amp;diff=2765&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/Thread_Join&amp;diff=2766&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/Thread_Join&amp;diff=2766&amp;oldid=prev"/>
				<updated>2010-05-31T15:18:03Z</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;==  Specify the number of milliseconds  to wait for the death of a 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;
class TryThread extends Thread {&lt;br /&gt;
  public TryThread(String firstName, String secondName, long delay) {&lt;br /&gt;
    this.firstName = firstName;&lt;br /&gt;
    this.secondName = secondName;&lt;br /&gt;
    aWhile = delay;&lt;br /&gt;
    setDaemon(true);&lt;br /&gt;
  }&lt;br /&gt;
  public void run() {&lt;br /&gt;
    try {&lt;br /&gt;
      while (total &amp;lt; 1000) {&lt;br /&gt;
        System.out.print(firstName);&lt;br /&gt;
        sleep(aWhile);&lt;br /&gt;
        total += aWhile;&lt;br /&gt;
        System.out.print(secondName + &amp;quot;\n&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
      System.out.print(secondName + &amp;quot; stoped.\n&amp;quot;);&lt;br /&gt;
    } catch (InterruptedException e) {&lt;br /&gt;
      System.out.println(firstName + secondName + e);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  private String firstName;&lt;br /&gt;
  private String secondName;&lt;br /&gt;
  private long aWhile;&lt;br /&gt;
  private long total;&lt;br /&gt;
}&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    Thread first = new TryThread(&amp;quot;A &amp;quot;, &amp;quot;a &amp;quot;, 200L);&lt;br /&gt;
    Thread second = new TryThread(&amp;quot;B &amp;quot;, &amp;quot;b &amp;quot;, 300L);&lt;br /&gt;
    Thread third = new TryThread(&amp;quot;C &amp;quot;, &amp;quot;c &amp;quot;, 500L);&lt;br /&gt;
    first.start();&lt;br /&gt;
    second.start();&lt;br /&gt;
    third.start();&lt;br /&gt;
    try {&lt;br /&gt;
      first.join(2000); // Wait up to 2 second for thread1 to die&lt;br /&gt;
    } catch (InterruptedException e) {&lt;br /&gt;
      e.printStackTrace();&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;
&amp;lt;pre class=codeResult&amp;gt;B A C a &lt;br /&gt;
A b &lt;br /&gt;
B a &lt;br /&gt;
A c &lt;br /&gt;
C a &lt;br /&gt;
A b &lt;br /&gt;
B a &lt;br /&gt;
A b &lt;br /&gt;
B c &lt;br /&gt;
c  stoped.&lt;br /&gt;
a &lt;br /&gt;
a  stoped.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Thread Join Demo ==&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;
Thread Joinclass TryThread extends Thread {&lt;br /&gt;
  public TryThread(String firstName, String secondName, long delay) {&lt;br /&gt;
    this.firstName = firstName;&lt;br /&gt;
    this.secondName = secondName;&lt;br /&gt;
    aWhile = delay;&lt;br /&gt;
    setDaemon(true);&lt;br /&gt;
  }&lt;br /&gt;
  public void run() {&lt;br /&gt;
    try {&lt;br /&gt;
      while (total &amp;lt; 1000) {&lt;br /&gt;
        System.out.print(firstName);&lt;br /&gt;
        sleep(aWhile);&lt;br /&gt;
        total += aWhile;&lt;br /&gt;
        System.out.print(secondName + &amp;quot;\n&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
      System.out.print(secondName + &amp;quot; stoped.\n&amp;quot;);&lt;br /&gt;
    } catch (InterruptedException e) {&lt;br /&gt;
      System.out.println(firstName + secondName + e);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  private String firstName;&lt;br /&gt;
  private String secondName;&lt;br /&gt;
  private long aWhile;&lt;br /&gt;
  private long total;&lt;br /&gt;
}&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    Thread first = new TryThread(&amp;quot;A &amp;quot;, &amp;quot;a &amp;quot;, 200L);&lt;br /&gt;
    Thread second = new TryThread(&amp;quot;B &amp;quot;, &amp;quot;b &amp;quot;, 300L);&lt;br /&gt;
    Thread third = new TryThread(&amp;quot;C &amp;quot;, &amp;quot;c &amp;quot;, 500L);&lt;br /&gt;
    first.start();&lt;br /&gt;
    second.start();&lt;br /&gt;
    third.start();&lt;br /&gt;
    try {&lt;br /&gt;
      first.join();&lt;br /&gt;
    } catch (InterruptedException e) {&lt;br /&gt;
      // TODO Auto-generated catch block&lt;br /&gt;
      e.printStackTrace();&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;
&amp;lt;pre class=codeResult&amp;gt;A B C a &lt;br /&gt;
A b &lt;br /&gt;
B a &lt;br /&gt;
A c &lt;br /&gt;
C a &lt;br /&gt;
A b &lt;br /&gt;
B a &lt;br /&gt;
A b &lt;br /&gt;
B c &lt;br /&gt;
c  stoped.&lt;br /&gt;
a &lt;br /&gt;
a  stoped.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Using join() to wait for threads to finish. ==&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 implements Runnable {&lt;br /&gt;
  String name; // name of thread&lt;br /&gt;
  Thread t;&lt;br /&gt;
  NewThread(String threadname) {&lt;br /&gt;
    name = threadname;&lt;br /&gt;
    t = new Thread(this, name);&lt;br /&gt;
    System.out.println(&amp;quot;New thread: &amp;quot; + t);&lt;br /&gt;
    t.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(name + &amp;quot;: &amp;quot; + i);&lt;br /&gt;
        Thread.sleep(1000);&lt;br /&gt;
      }&lt;br /&gt;
    } catch (InterruptedException e) {&lt;br /&gt;
      System.out.println(name + &amp;quot; interrupted.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(name + &amp;quot; exiting.&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class DemoJoin {&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    NewThread ob1 = new NewThread(&amp;quot;One&amp;quot;);&lt;br /&gt;
    NewThread ob2 = new NewThread(&amp;quot;Two&amp;quot;);&lt;br /&gt;
    NewThread ob3 = new NewThread(&amp;quot;Three&amp;quot;);&lt;br /&gt;
    System.out.println(&amp;quot;Thread One is alive: &amp;quot; + ob1.t.isAlive());&lt;br /&gt;
    System.out.println(&amp;quot;Thread Two is alive: &amp;quot; + ob2.t.isAlive());&lt;br /&gt;
    System.out.println(&amp;quot;Thread Three is alive: &amp;quot; + ob3.t.isAlive());&lt;br /&gt;
    try {&lt;br /&gt;
      System.out.println(&amp;quot;Waiting for threads to finish.&amp;quot;);&lt;br /&gt;
      ob1.t.join();&lt;br /&gt;
      ob2.t.join();&lt;br /&gt;
      ob3.t.join();&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;Thread One is alive: &amp;quot; + ob1.t.isAlive());&lt;br /&gt;
    System.out.println(&amp;quot;Thread Two is alive: &amp;quot; + ob2.t.isAlive());&lt;br /&gt;
    System.out.println(&amp;quot;Thread Three is alive: &amp;quot; + ob3.t.isAlive());&lt;br /&gt;
    System.out.println(&amp;quot;Main thread exiting.&amp;quot;);&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;
==  Wait for the threads to finish ==&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;
public class Main {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    Thread thread1 = new Thread(new TestThread(1));&lt;br /&gt;
    Thread thread2 = new Thread(new TestThread(2));&lt;br /&gt;
    thread1.start();&lt;br /&gt;
    thread2.start();&lt;br /&gt;
    thread1.join();&lt;br /&gt;
    thread2.join();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class TestThread implements Runnable {&lt;br /&gt;
  int id;&lt;br /&gt;
  public TestThread(int id) {&lt;br /&gt;
    this.id = id;&lt;br /&gt;
  }&lt;br /&gt;
  public void run() {&lt;br /&gt;
    for (int i = 1; i &amp;lt;= 10; i++) {&lt;br /&gt;
      System.out.println(&amp;quot;Thread&amp;quot; + id + &amp;quot;: &amp;quot; + i);&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;
==  Wait the for the completion of a 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;
public class Main {&lt;br /&gt;
  public static void main(String a[]) throws Exception {&lt;br /&gt;
    MyThread tt1 = new MyThread(50);&lt;br /&gt;
    MyThread tt2 = new MyThread(75);&lt;br /&gt;
    Thread t1 = new Thread(tt1, &amp;quot;Test thread 1&amp;quot;);&lt;br /&gt;
    Thread t2 = new Thread(tt2, &amp;quot;Test thread 2&amp;quot;);&lt;br /&gt;
    t1.start();&lt;br /&gt;
    t2.start();&lt;br /&gt;
    t1.join();&lt;br /&gt;
    t2.join();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class MyThread implements Runnable {&lt;br /&gt;
  int i;&lt;br /&gt;
  MyThread(int i) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.i = i;&lt;br /&gt;
  }&lt;br /&gt;
  public void run() {&lt;br /&gt;
     System.out.println(Thread.currentThread().getName() + &amp;quot; &amp;quot; + i);&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>