Q: One Thread Waiting on Method of Another I have one thread(A) that kicks off another (B). Thread A must wait for thread B's initialisation method to complete before it continues on.
I am currently using thread B as a lock like so:
synchronized (B) {

            try {

                B.start();

                while (!B.getIsInitialized()) {
                    B.wait();
                }
            } catch (InterruptedException e) {
                Log.logStackTrace(this + " run: Exception detected", e);
            }
        }

At the very beginning of B's run method, I have the following:
synchronized(this) {

        initialize();

        notify();
    }

This all seems to work, but I can;t find anything online about using one of the two threads as the lock. Is what I'm doing correct? I should also note that thread B does not terminate once initialisation is complete, and needs to continue on so I can't simply use .join().
Thank you for your time.

A: This code will work definitely,for what you want to achieve. The only think I will mention is that try to use synchronized as less as you can because synchronization is 'expensive'. So if some part of code is not need to be in synchronized part then don't.  This part of code will do the same but synchronization is done only in thread B. 
public class Test {
 public static void main(String[] args) {       
     new ThreadA().start();
  }
}


class ThreadA extends Thread{       
    private void startThreadB(){
        ThreadB tb=new ThreadB();
        tb.start();                 
        // to some code if you need;
        tb.isInit();
    }

    public void run(){
            System.out.println("Thread A is started ");
            startThreadB(); 
            while(true){
                // your code for execution of thread A
                System.out.println("thread A is working");
                try{ Thread.sleep(2000);} catch(Exception e){}
            }
    }       
}



  class ThreadB extends Thread{
     private boolean init;               
     public ThreadB(){   init=false;     }
     private void init(){
         // some code here for init
         synchronized(this){
               init= true;
               notifyAll();
               System.out.println("Thread B has been inicialized !");
         }
     }


     public void isInit(){
         synchronized(this){
             while(!init) { try{ wait();}catch(InterruptedException e){}}
         }
     }

    public void run(){
        System.out.println("Thread B is started");
        init();
        while(true){
            // your code for execution of thread B
            System.out.println("Thread B is working");
            try{ Thread.sleep(2000);} catch(Exception e){}
        }
    }
}

