Java 线程连接不工作

Java 线程连接不工作,java,multithreading,join,Java,Multithreading,Join,下面代码的逻辑是否有错误?根据线程是否处于活动状态,尝试使用联接。代码将进入无限循环。我是新来的线程不确定的逻辑是正确的或不是,试图参考许多文章,我无法解决它 protected static HashMap<Integer, Object> MatchMap = new HashMap<Integer, Object>(); synchronized(this) { //HashMap<String, Object> MatchMap

下面代码的逻辑是否有错误?根据线程是否处于活动状态,尝试使用联接。代码将进入无限循环。我是新来的线程不确定的逻辑是正确的或不是,试图参考许多文章,我无法解决它

protected static HashMap<Integer, Object> MatchMap = new HashMap<Integer, Object>();
synchronized(this)
    {
        //HashMap<String, Object> MatchMap = new HashMap<String, Object>();
        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>>>"+ this_object);
        try{
        while (1==1)
        //for(int n=0; n<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>>>"+at.getId());
                }
                else
                {
                    MatchMap.remove(cstd_tsk);
                    MatchMap.put(new Integer(this.CSTDN_ID), (Object)Thread.currentThread());
                    log.error("tsk not_alive>>>");
                    break;
                }                               
            }
            else
            {
                MatchMap.put(new Integer(this.CSTDN_ID), (Object)Thread.currentThread());
                log.error("tsk does not contain>>>"+Thread.currentThread().getId());
                break;
            }
        }
        }
        catch(Exception e)
        {
            e.printStackTrace();
            log.error("Stack trace is - " + e);
            //System.out.println(e);
        }
    }
protected static HashMap MatchMap=new HashMap();
已同步(此)
{
//HashMap MatchMap=新HashMap();
字符串this_object=“”;
线程在;
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(“此对象>>>”+此对象);
试一试{
而(1==1)

//for(int n=0;njoin等待这个线程死亡。 而不是

Thread.currentThread().join();

而(1==1)


这就是您的问题:)

确保正确处理
中断异常
请添加其他人可以在其机器上轻松编译和执行的代码。请阅读
at.join();