title: Java Executing one thread and make others on waiting mode
body: <p>So I have a block of code that contains a <code>method</code> which allows users to search for a record's value from the database,
  If the record exist an exception will be generated
  Else the record will be added to the table.</p>
  <p>So what I want to do is to stop all threads in the search <code>method</code>, and let only one thread to add the record into the table, and the that Thread is done I will call the <code>.notify</code> method to wake the other threads.</p>
  <blockquote>
  <p>let's consider this is my code</p>
  </blockquote>
  <pre><code>    //first step
         public static Object locker= new locker();
    -1     synchronized(locker){                              
    -2     res = ps.executeQuery();
    -3      lock.wait()
          }
      
      //second step 
     -4  dbaccess.add(record) // let's consider this will add my record to the table
     -5  lock.notify();
  </code></pre>
  <p>with this code the thread will be stuck and never executed what i want to do is to make one works and others waiting until I call the notify() in the 5th step</p>