多线程问题(线程A产生 线程B,如何保证线程B执行完后再继续往下执行线程A?)
如Athread
{
System.out.println("A");
new Bthread();
System.out.println("AA");}
上面不是代码,形象的表达我的观点而以。
如何保证A,B线程异步呢。
谢谢

解决方案 »

  1.   

    可以把B线程的级别调高点public class ThreadA extends Thread{
    public void run(){
    ThreadB threadB=new ThreadB();
    threadB.setPriority(6);
    threadB.start();
    System.out.println("ThreadA:"+Thread.currentThread().getName());
    }
    }
    public class ThreadB extends Thread{
    public void run(){
    System.out.println("ThreadB:"+Thread.currentThread().getName());
    }
    }
    public class Test {
    public static void main(String args[]){
    ThreadA threadA=new ThreadA();
    threadA.start();
    }
    }
      

  2.   

    线程的同步的问题,可以用,wait,notify来同步
      

  3.   

    public class ThreadA extends Thread{
        public void run(){
            System.out.println("ThreadA:"+Thread.currentThread().getName());
        }
    }
    public class ThreadB extends Thread{
        public void run(){
            System.out.println("ThreadB:"+Thread.currentThread().getName());
        }
    }
    public class Test throws InterruptedException{
        public static void main(String args[]){
            ThreadA threadA=new ThreadA();
            ThreadB threadB=new ThreadB();
            threadA.start();
            ThreadA.sleep(3);//开启A线程后休眠一段时间,在让B线程开启呢!
            threadB.start();
            
        }
    }