title: Thread Join not working
body: <p>Is there any error in the logic of below code ? Trying to use join depending on thread is alive or not. Code is going to infinite loop. I am new to threads not sure about the logic is correct or not, tried referring many articles i couldn't solve it.</p>
  
  <pre><code>protected static HashMap&lt;Integer, Object&gt; MatchMap = new HashMap&lt;Integer, Object&gt;();
  synchronized(this)
      {
          //HashMap&lt;String, Object&gt; MatchMap = new HashMap&lt;String, Object&gt;();
          String this_object = "";
          Thread at ;
          int cstd_tsk= 0;
          cstd_tsk = this.CSTDN_ID;
  
          this_object = this.SCA_REF + ":" + this.INSTRMNT_ID + ":" +  this.CSTDN_ID + ":" + this.TXN_TYPE;
  
          log.error("this_object&gt;&gt;&gt;"+ this_object);
          try{
          while (1==1)
          //for(int n=0; n&lt;100; n++)
          {                               
              if(MatchMap.containsKey(cstd_tsk))
              {
              /*  Thread.currentThread().join();
                  MatchMap.remove(this_object);
                  MatchMap.put(this_object, (Object)Thread.currentThread());
              */  
                at = (Thread)MatchMap.get(cstd_tsk);
                  if(at.isAlive())
                  {
                   Thread.currentThread().join();
                   log.error("tsk is_alive&gt;&gt;&gt;"+at.getId());
                  }
                  else
                  {
                      MatchMap.remove(cstd_tsk);
                      MatchMap.put(new Integer(this.CSTDN_ID), (Object)Thread.currentThread());
                      log.error("tsk not_alive&gt;&gt;&gt;");
                      break;
                  }                               
              }
              else
              {
                  MatchMap.put(new Integer(this.CSTDN_ID), (Object)Thread.currentThread());
                  log.error("tsk does not contain&gt;&gt;&gt;"+Thread.currentThread().getId());
                  break;
              }
          }
          }
          catch(Exception e)
          {
              e.printStackTrace();
              log.error("Stack trace is - " + e);
              //System.out.println(e);
          }
      }
  </code></pre>