Intuit Interview Question for Senior Software Development Engineers


Country: United States




Comment hidden because of low score. Click to expand.
1
of 1 vote

1) Join()=> the current thread has to wait for the thread's object exit status.
2) wait()=> wait() tells the calling thread to give up the monitor and go to sleep until some other thread enters the same monitor and calls notify( ).
3) Sleep()=> it hold the current thread execution.
Wait() releases the lock() of the moniter

- yogi.rulzz September 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

1) Join(): this method waits for a thread to die. for example:

t1.start();  
 try{  
  t1.join();  
 }catch(Exception e){System.out.println(e);}  
  
 t2.start();  
 t3.start();

Here, at first t1 thread completes it execution then the t2 and t3 starts there execution.

2) wait(): when this method is called that means it waits for a thread to be completed. Normally this method is used where there is needed synchronize execution. for example:

public class ThreadA {
    public static void main(String[] args){
        ThreadB b = new ThreadB();
        b.start();
 
        synchronized(b){
            try{
                System.out.println("Waiting for b to complete...");
                b.wait();
            }catch(InterruptedException e){
                e.printStackTrace();
            }
 
            System.out.println("Total is: " + b.total);
        }
    }
}
 
class ThreadB extends Thread{
    int total;
    @Override
    public void run(){
        synchronized(this){
            for(int i=0; i<100 ; i++){
                total += i;
            }
            notify();
        }
    }
}

In the above code, when b thread finishes its operation then it calls the notify() method. Then the wait() method terminates the waiting.
If you conceptually want to understand, then you can consider the producer and consumer problem where consumer waits for a product to be produced by the producer. That means, when producer notify the consumers only then the consumers can consume the products.

3) sleep(ms): Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.

- Md. Mahedi Kaysar September 25, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More