2

我已经厌倦了这个问题,并最终提出了一些疑问。请帮帮我

疑问:如果任何线程处于等待状态,并且没有其他线程通知该线程,那么它永远不会结束吗?即使在使用等待(长毫秒)之后。

对于代码:我的要求来自代码(请参考我的代码):

a : 应该打印“Even Thread Finish”和“Odd Thread Finish”(顺序不是 imp ,但必须同时打印)

b: 在 main 函数中也应该打印“Exit Main Thread”

实际发生的情况:经过大量运行后,在某些情况下,它会打印“Even Thread Finish”然后挂在这里,反之亦然。在某些情况下,它会同时打印两者。

它也从不打印“退出主线程”。

那么如何修改代码,所以它必须打印所有 3 条语句。(当然最后是“Exit Main..”,因为我正在使用 join 作为 main。)

简而言之:主要开始-> t1 开始-> t2 开始,然后我需要 t2/t1 完成-> 主要完成。

请帮我解决这个问题

这是我的代码:

import javax.sql.CommonDataSource;

public class ThreadTest {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Share commonObj = new Share();

        Thread even = new Thread(new EvenThread(commonObj));

        Thread odd = new Thread(new OddThread(commonObj));

        even.start();

        odd.start();

        try {
            Thread.currentThread().join();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        System.out.println("Exit Main Thread");

    }

}

class EvenThread implements Runnable {

    private Share commShare;
    public EvenThread(Share obj) {
        // TODO Auto-generated constructor stub
        this.commShare = obj;
    }

    private int number = 2;

    public void run() {
        System.out.println("Even Thread start");
        while (number <= 50) {
            if (commShare.flag == true) {
                System.out.println("Even Thread" + number);
                number += 2;
                commShare.flag = false;
                synchronized(commShare) {
                    try {
                        commShare.notify();
                        commShare.wait();
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    commShare.notify();
                }

            } else {
                synchronized(commShare) {
                    try {
                        commShare.notify();
                        commShare.wait();
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    commShare.notify();
                }
            }

        }

        System.out.println("Even Thread Finish");
    }
}


class OddThread implements Runnable {

    private int number = 1;
    private Share commShare;


    public OddThread(Share obj) {
        // TODO Auto-generated constructor stub
        this.commShare = obj;
    }



    public void run() {
        System.out.println("Odd Thread start");
        while (number <= 50) {
            if (commShare.flag == false) {
                System.out.println("Odd Thread :" + number);
                number += 2;
                commShare.flag = true;
                synchronized(commShare) {
                    try {
                        commShare.notify();
                        commShare.wait();
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    commShare.notify();
                }
            }
        }
        System.out.println("Odd Thread Finish");
    }
}

class Share {

    Share sharedObj;
    public boolean flag = false;
}
4

13 回答 13

3

虽然这不是您问题的确切答案,但此实现是您问题的替代方案。

public class EvenOddThreads {
    public static void main(String[] args) {
        Thread odd = new Thread(new OddThread(), "oddThread");

        Thread even = new Thread(new EvenThread(), "Even Thread");

        odd.start();
        even.start();
        try {
            odd.join();
            even.join();
            System.out.println("Main thread exited");
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
class OddThread implements Runnable{
    public void run() {
        synchronized (CommonUtil.mLock) {
            System.out.println(Thread.currentThread().getName()+"---> job starting");
            int i = 1;
            while(i<50){
                System.out.print(i + "\t");
                i = i + 2;
                CommonUtil.mLock.notify();
                try {
                    CommonUtil.mLock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("OddThread---> job completed");
            CommonUtil.mLock.notify();

        }
    }
}

class EvenThread implements Runnable{
    @Override
    public void run() {
        synchronized (CommonUtil.mLock) {
            System.out.println(Thread.currentThread().getName()+"---> job started");
            int i =2;
            while(i<50){
                System.out.print(i + "\t");
                i = i+2;
                CommonUtil.mLock.notify();
                try {
                    CommonUtil.mLock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("EvenThread---> job completed");
            CommonUtil.mLock.notify();
        }
    }
}

class CommonUtil{
    static final Object mLock= new Object();
}

输出:

oddThread---> job starting
1   Even Thread---> job started
2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  EvenThread---> job completed
OddThread---> job completed
Main thread exited
于 2013-09-14T08:44:49.337 回答
1

好吧,我花了三个小时阅读Java 同步教程(一个非常好的教程),然后是有关wait、notify 和 notifyAll的更多信息,最后我得到了使用 N 个线程从 A 计数到 B 的程序,将 N 设置为2 你有奇数和偶数。

糊盒

此外,我的程序没有任何注释,因此请确保在尝试理解此代码之前阅读教程。

于 2013-09-14T13:00:07.517 回答
0

它也从不打印“退出主线程”。

那是因为可能是因为您的线程正在等待某人锁定,notify()但由于错过了信号或没有人向他们发出信号,它们永远不会退出等待状态。为此,最好的解决方案是使用:

public final void wait(long timeout)
                throws InterruptedException

使当前线程等待,直到另一个线程调用该notify()方法或notifyAll()此对象的方法,或者经过了指定的时间量。

这个重载的方法将等待其他线程通知特定的时间量,然后如果发生超时则返回。因此,在丢失信号的情况下,线程仍将恢复其工作。

注意:从等待状态返回后,请务必再次检查 PRE-CONDITION,因为它可能是Spurious Wakeup

这是我在一段时间前编写的程序风格。

import java.util.concurrent.atomic.AtomicInteger;


public class Main {

    private static int range = 10;
    private static volatile AtomicInteger present = new AtomicInteger(0);
    private static Object lock = new Object();

    public static void main(String[] args) {
        new Thread(new OddRunnable()).start();
        new Thread(new EvenRunnable()).start();
    }

    static class OddRunnable implements Runnable{

        @Override
        public void run() {
            while(present.get() <= range){
                if((present.get() % 2) != 0){
                    System.out.println(present.get());
                    present.incrementAndGet();
                    synchronized (lock) {
                        lock.notifyAll();
                    }
                }else{
                    synchronized (lock) {
                        try {
                            lock.wait(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                            break;
                        }
                    }
                }
            }
        }
    }

    static class EvenRunnable implements Runnable{

        @Override
        public void run() {
            while(present.get() <= range){
                if((present.get() % 2) == 0){
                    System.out.println(present.get());
                    present.incrementAndGet();
                    synchronized (lock) {
                        lock.notifyAll();
                    }
                }else{
                    synchronized (lock) {
                        try {
                            lock.wait(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                            break;
                        }
                    }
                }
            }
        }
    }
}

查看解决方案,我保留了一个lock用于通知偶数或奇数线程的机会。如果偶数线程发现当前数字不是偶数,它会等待lock并希望奇数线程在打印该奇数时通知它。同样,它也适用于奇数线程。

我并不是说这是最好的解决方案,但这是第一次尝试时出现的问题,其他一些选择也是可能的。

另外我想指出,这个问题虽然作为一种实践是好的,但请记住,你并没有在那里做任何平行的事情。

于 2013-09-14T12:20:20.250 回答
0
public class PrintNumbers {

    public static class Condition {
        private boolean start = false;
        public boolean getStart() {
            return start;
        }

        public void setStart(boolean start) {
            this.start = start;
        }
    }

    public static void main(String[] args) {

        final Object lock = new Object();
        // condition used to start the odd number thread first
        final Condition condition = new Condition();

        Thread oddThread = new Thread(new Runnable() {
            public void run() {
                synchronized (lock) {
                    for (int i = 1; i <= 10; i = i + 2) { //For simplicity assume  only printing till 10;
                        System.out.println(i);
                        //update condition value to signify that odd number thread has printed first
                        if (condition.getStart() == false) {
                            condition.setStart(true);
                        }
                        lock.notify();
                        try {
                            if (i + 2 <= 10) { 
                                lock.wait(); //if more numbers to print, wait;
                            }
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }

        });

        Thread evenThread = new Thread(new Runnable() {
            public void run() {
                synchronized (lock) {
                    for (int i = 2; i <= 10; i = i + 2) { //For simplicity assume only printing till 10;
                        // if thread with odd number has not printed first, then wait
                        while (condition.getStart() == false) {
                            try {
                                lock.wait();
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                        System.out.println(i);
                        lock.notify();
                        try {
                            if (i + 2 <= 10) { //if more numbers to print, wait;
                                lock.wait();
                            }
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }

        });

        oddThread.start();
        evenThread.start();

    }

}
于 2013-10-18T05:56:44.843 回答
0

这可能是一个关于线程和锁监视器的练习,但没有什么可以并行进行的,这会给您带来优势。

在您的代码中,当线程 1(OddThread 或 EvenThread)结束他的工作并打印出“Odd Thread Finish”(或“Even Thread Finish”)时,另一个线程 2 正在等待永远不会发生的 notify() 或 notifyAll()因为第一个已经结束。

您必须更改 EvenThread 和 OddThread,在 while 循环之后添加一个同步块,并在 commShare 上进行通知调用。我删除了第二个 if 分支,因为这样你就不会继续检查 while 条件,而是很快就会等待 commShare。

class EvenThread implements Runnable {
    private Share commShare;
    private int number = 2;

    public EvenThread(Share obj) {
        this.commShare = obj;
    }
    public void run() {
        System.out.println("Even Thread start");
        while (number <= 50) {
            synchronized (commShare) {
                if (commShare.flag) {
                    System.out.println("Even Thread:" + number);
                    number += 2;
                    commShare.flag = false;
                }
                commShare.notify();
                try {
                    commShare.wait();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        synchronized (commShare) {
            commShare.notify();
            System.out.println("Even Thread Finish");
        }
    }
}

class OddThread implements Runnable {
    private int number = 1;
    private Share commShare;

    public OddThread(Share obj) {
        this.commShare = obj;
    }
    public void run() {
        System.out.println("Odd Thread start");
        while (number <= 50) {
            synchronized (commShare) {
                if (!commShare.flag) {
                    System.out.println("Odd Thread: " + number);
                    number += 2;
                    commShare.flag = true;
                }
                commShare.notify();
                try {
                    commShare.wait();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        }
        synchronized (commShare) {
            commShare.notify();
            System.out.println("Odd Thread Finish");
        }
    }

最后,在主线程中,您必须为您启动的每个线程加入。确定 Thread.currentThread() 只返回您的一个线程?我们已经启动了两个线程以及我们应该加入的线程。

try {
      even.join();
      odd.join();
} catch (InterruptedException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
}
于 2013-09-14T08:40:27.807 回答
0

我不会投票赞成使用wait()notify().你可以做的事情,wait并且notify可以通过更复杂的工具来完成,比如semaphore,,。您可以在着名的书 Effective java 中的第 69 项中找到这个建议,更喜欢并发实用程序来等待和通知countDownLatchCyclicBarrier

即使在这种情况下我们根本不需要这些东西,我们可以通过一个简单的变量来实现这个功能。volatile boolean而要停止线程,最好的方法是使用interrupt. 在一定的时间或一些预定义的条件后,我们可以中断线程。请在附件中找到我的实现:

打印偶数的线程 1:

public class MyRunnable1 implements Runnable
{
    public static volatile boolean isRun = false;
    private int k = 0 ;
    @Override
    public void run() {
        while(!Thread.currentThread().isInterrupted()){
            if(isRun){
                System.out.println(k);
                k+=2;
                isRun=false;
                MyRunnable2.isRun=true;
            }
        }
    }
}

线程 2 用于打印偶数:

public class MyRunnable2 implements Runnable{
    public static volatile boolean isRun = false;
    private int k = 1 ;
    @Override
    public void run() {
        while(!Thread.currentThread().isInterrupted()){
            if(isRun){
                System.out.println(k);
                k+=2;
                isRun=false;
                MyRunnable1.isRun=true;
            }
        }
    }
}

现在驱动上述线程的主要方法

public class MyMain{
    public static void main(String[] args) throws InterruptedException{
        Thread t1 = new Thread(new MyRunnable1());
        Thread t2 = new Thread(new MyRunnable2());
        MyRunnable1.isRun=true;
        t1.start();
        t2.start();
        Thread.currentThread().sleep(1000);
        t1.interrupt();
        t2.interrupt();
    }
}

可能有些地方你需要改变一下,这只是一个骨架实现。希望它有所帮助,如果您需要其他东西,请告诉我。

于 2013-09-15T00:49:09.720 回答
0

我尝试了类似的东西,其中线程 1 打印奇数,线程 2 以正确的顺序打印偶数,并且当打印结束时,将打印您建议的所需消息。请看一下这段代码

package practice;


class Test {

  private static boolean oddFlag = true;
  int count = 1;

  private void oddPrinter() {
    synchronized (this) {
      while(true) {
        try {
          if(count < 10) {
            if(oddFlag) {
              Thread.sleep(500);
              System.out.println(Thread.currentThread().getName() + ": " + count++);
              oddFlag = !oddFlag;
              notifyAll();
            }
            else {
              wait();
            }
          }
          else {
            System.out.println("Odd Thread finished");
            notify();
            break;
          }
        }
        catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
  }

  private void evenPrinter() {
    synchronized (this) {
      while (true) {
        try {
          if(count < 10) {
            if(!oddFlag) {
              Thread.sleep(500);
              System.out.println(Thread.currentThread().getName() + ": " + count++);
              oddFlag = !oddFlag;
              notify();
            }
            else {
              wait();
            }
          }
          else {
            System.out.println("Even Thread finished");
            notify();
            break;
          }
        }
        catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
  }


  public static void main(String[] args) throws InterruptedException{
    final Test test = new Test();

    Thread t1 = new Thread(new Runnable() {
      public void run() {
        test.oddPrinter();
      }
    }, "Thread 1");

    Thread t2 = new Thread(new Runnable() {
      public void run() {
        test.evenPrinter();
      }
    }, "Thread 2");

    t1.start();
    t2.start();

    t1.join();
    t2.join();

    System.out.println("Main thread finished");
  }
}
于 2017-10-02T05:33:58.987 回答
0

这是非常通用的解决方案。它使用信号量在线程之间做信号。这是 N 个线程依次依次打印 M 个自然数的通用解决方案。也就是说,如果我们有 3 个线程并且我们想要打印 7 个自然数,输出将是:

线程 1:1

线程 2:2

主题 3 : 3

线程 1 : 4

线程 2 : 5

线程 3 : 6

线程 1 : 7

import java.util.concurrent.Semaphore;

/*
 * Logic is based on simple idea
 * each thread should wait for previous thread and then notify next thread in circular fashion
* There is no locking required
* Semaphores will do the signaling work among threads.
*/

public class NThreadsMNaturalNumbers {

private static volatile int nextNumberToPrint = 1;
private static int MaxNumberToPrint;

public static void main(String[] args) {

    int numberOfThreads = 2;
    MaxNumberToPrint = 50;

    Semaphore s[] = new Semaphore[numberOfThreads];

    // initialize Semaphores
    for (int i = 0; i < numberOfThreads; i++) {
        s[i] = new Semaphore(0);
    }

    // Create threads and initialize which thread they wait for and notify to
    for (int i = 1; i <= numberOfThreads; i++) {
        new Thread(new NumberPrinter("Thread " + i, s[i - 1], s[i % numberOfThreads])).start();
    }
    s[0].release();// So that First Thread can start Processing
}

private static class NumberPrinter implements Runnable {

    private final Semaphore waitFor;
    private final Semaphore notifyTo;
    private final String name;

    public NumberPrinter(String name, Semaphore waitFor, Semaphore notifyTo) {
        this.waitFor = waitFor;
        this.notifyTo = notifyTo;
        this.name = name;
    }

    @Override
    public void run() {

        while (NThreadsMNaturalNumbers.nextNumberToPrint <= NThreadsMNaturalNumbers.MaxNumberToPrint) {
            waitFor.acquireUninterruptibly();
            if (NThreadsMNaturalNumbers.nextNumberToPrint <= NThreadsMNaturalNumbers.MaxNumberToPrint) {
                System.out.println(name + " : " + NThreadsMNaturalNumbers.nextNumberToPrint++);
                notifyTo.release();
            }

        }
        notifyTo.release();
    }

}

}

于 2018-09-30T19:48:17.357 回答
0

我使用带有 25 个线程的 ReentrantLock 做到了。一个线程打印一个号码,它会通知其他人。

public class ReentrantLockHolder 
{
    private Lock lock;

    private Condition condition;

    public ReentrantLockHolder(Lock lock )
    {
        this.lock=lock;
        this.condition=this.lock.newCondition();
    }

    public Lock getLock() {
        return lock;
    }

    public void setLock(Lock lock) {
        this.lock = lock;
    }

    public Condition getCondition() {
        return condition;
    }

    public void setCondition(Condition condition) {
        this.condition = condition;
    }
}
public class PrintThreadUsingReentrantLock implements Runnable
{
    private ReentrantLockHolder currHolder;

    private ReentrantLockHolder nextHolder;

    private PrintWriter writer;

    private static int i=0;

    public PrintThreadUsingReentrantLock(ReentrantLockHolder currHolder, ReentrantLockHolder nextHolder ,PrintWriter writer)
    {
        this.currHolder=currHolder;
        this.nextHolder=nextHolder;
        this.writer=writer;
    }

    @Override
    public void run() 
    {
        while (true) 
        {
            writer.println(Thread.currentThread().getName()+ " "+ ++i);

            try{
                nextHolder.getLock().lock();
                nextHolder.getCondition().signal();
            }finally{
                nextHolder.getLock().unlock();  
            }

            try {
                currHolder.getLock().lock();
                currHolder.getCondition().await();
            }catch (InterruptedException e) 
            {
                e.printStackTrace();
            }
            finally{
                currHolder.getLock().unlock();
            }
        }
    }
}
public static void main(String[] args) 
    {
        PrintWriter printWriter =null;
        try {
                printWriter=new PrintWriter(new FileOutputStream(new File("D://myFile.txt")));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        ReentrantLockHolder obj[]=new ReentrantLockHolder[25];
        for(int i=0;i<25;i++)
        {
            obj[i]=new ReentrantLockHolder(new ReentrantLock());
        }

        for(int i=0;i<25;i++)
        {
            Thread t1=new Thread(new PrintThreadUsingReentrantLock(obj[i], obj[i+1 == 25 ? 0 : i+1],printWriter ),"T"+i );
            t1.start();
        }
    }
于 2016-03-04T07:21:12.143 回答
0

这个类打印偶数:

public class EvenThreadDetails extends Thread{

    int countNumber;
     public EvenThreadDetails(int countNumber) {
        this.countNumber=countNumber;
    }
    @Override
    public void run()
    {
        for (int i = 0; i < countNumber; i++) {
            if(i%2==0)
            {
                System.out.println("Even Number :"+i);
            }
            try {
                Thread.sleep(2);
            } catch (InterruptedException ex) {
                // code to resume or terminate...
            }
        }
    }
}

    

这个类打印奇数:

public class OddThreadDetails extends Thread {

    int countNumber;
     public OddThreadDetails(int countNumber) {
        this.countNumber=countNumber;
    }
    @Override
    public void run()
    {
        for (int i = 0; i < countNumber; i++) {
            if(i%2!=0)
            {
                System.out.println("Odd Number :"+i);
            }
            try {
                Thread.sleep(2);
            } catch (InterruptedException ex) {
                // code to resume or terminate...
            }       
        }
    }
}

这是主类:

public class EvenOddDemo {

    public static void main(String[] args) throws InterruptedException
    {
        Thread eventhread= new EvenThreadDetails(100);
        Thread oddhread=new OddThreadDetails(100);
        eventhread.start();
        oddhread.start();   
    }
}
于 2020-09-06T10:04:32.027 回答
0
package test;

public class Interview2 {

public static void main(String[] args) {
    Obj obj = new Obj();

    Runnable evenThread = ()-> {
        synchronized (obj) {
            for(int i=2;i<=50;i+=2) {
                while(!obj.printEven) {
                    try {
                        obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }                   
                }
                System.out.println(i);
                obj.printEven = false;
                obj.notify();
            }
        }           
    };
    Runnable oddThread = ()-> {
        synchronized (obj) {
            for(int i=1;i<=49;i+=2) {
                while(obj.printEven) {
                    try {
                        obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }                   
                }
                System.out.println(i);
                obj.printEven = true;
                obj.notify();
            }
        }
    };      
    new Thread(evenThread).start();
    new Thread(oddThread).start();
   }
}
class Obj {
  boolean printEven;
}
于 2018-06-20T16:20:59.180 回答
-1
I have done it this way and its working...

class Printoddeven{

public synchronized void print(String msg){
    try {
        if(msg.equals("Even"))
        {
        for(int i=0;i<=10;i+=2){
            System.out.println(msg+" "+i);
            Thread.sleep(2000);
            notify();
            wait();
        }
        }

        else{
            for(int i=1;i<=10;i+=2){
                System.out.println(msg+" "+i);
                Thread.sleep(2000);
                notify();
                wait();
            }
        }

    } catch (Exception e) {

        e.printStackTrace();
    }
}

}

class PrintOdd extends Thread{
Printoddeven oddeven;
public PrintOdd(Printoddeven oddeven){
    this.oddeven=oddeven;
}

public void run(){
    oddeven.print("ODD");

}

}

class PrintEven extends Thread{
Printoddeven oddeven;
public PrintEven(Printoddeven oddeven){
    this.oddeven=oddeven;
}

public void run(){
    oddeven.print("Even");

}

}



public class mainclass 
{

public static void main(String[] args) 
{

    Printoddeven obj = new Printoddeven();//only one object  
    PrintEven t1=new PrintEven(obj);  
    PrintOdd t2=new PrintOdd(obj);  
    t1.start();  
    t2.start();  

}
}
于 2014-12-23T07:16:14.433 回答
-1
public class Driver {
    static Object lock = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(new Runnable() {
            public void run() {

                for (int itr = 1; itr < 51; itr = itr + 2) {
                    synchronized (lock) {
                        System.out.print(" " + itr);
                        try {
                            lock.notify();
                            lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
                System.out.println("\nEven Thread Finish ");
            }
        });
        Thread t2 = new Thread(new Runnable() {
            public void run() {

                for (int itr = 2; itr < 51; itr = itr + 2) {
                    synchronized (lock) {
                        System.out.print(" " + itr);
                        try {
                            lock.notify();
                            if(itr==50)
                                break;
                            lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
                System.out.println("\nOdd Thread Finish ");
            }
        });
        try {
            t1.start();
            t2.start();
            t1.join();
            t2.join();
            System.out.println("Exit Main Thread");
        } catch (Exception e) {

        }
    }
}
于 2015-06-12T19:59:49.560 回答