private java.lang.Object __equalsCalc = null;
    public synchronized boolean equals(java.lang.Object obj) {
        if (!(obj instanceof Ad)) return false;
        Ad other = (Ad) obj;
        if (obj == null) return false;
        if (this == obj) return true;
        if (__equalsCalc != null) {
            return (__equalsCalc == obj);
        }
        __equalsCalc = obj;

        boolean _equals;
        _equals = true && 
            this.adGroupId == other.getAdGroupId() &&
            ((this.adType==null && other.getAdType()==null) || 
             (this.adType!=null &&
              this.adType.equals(other.getAdType()))) &&
            ((this.destinationUrl==null && other.getDestinationUrl()==null) || 
             (this.destinationUrl!=null &&
              this.destinationUrl.equals(other.getDestinationUrl()))) &&
            this.disapproved == other.isDisapproved() &&
            ((this.displayUrl==null && other.getDisplayUrl()==null) || 
             (this.displayUrl!=null &&
              this.displayUrl.equals(other.getDisplayUrl()))) &&
            ((this.exemptionRequest==null && other.getExemptionRequest()==null) || 
             (this.exemptionRequest!=null &&
              this.exemptionRequest.equals(other.getExemptionRequest()))) &&
            this.id == other.getId() &&
            ((this.status==null && other.getStatus()==null) || 
             (this.status!=null &&
              this.status.equals(other.getStatus())));
        __equalsCalc = null;
        return _equals;
    }

解决方案 »

  1.   

    会啊,__equalsCalc可被任何不请求该equals方法所属对象监视锁的线程在任何时刻修改
      

  2.   

    __equalsCalc只是被初始化为null,可以被修改,它的定义并没有出现在synchronized修饰的equals方法里
      

  3.   

    public synchronized boolean equals(java.lang.Object obj) { 
    //对__equalsCalc加锁
    synchronized (equalsCalc )
            if (!(obj instanceof Ad)) return false; 
            Ad other = (Ad) obj; 
            if (obj == null) return false; 
            if (this == obj) return true; 
          if (__equalsCalc != null) { 
                return (__equalsCalc == obj); 
            } 
            __equalsCalc = obj; 
            boolean _equals; 
            _equals = true && 
                this.adGroupId == other.getAdGroupId() && 
                ((this.adType==null && other.getAdType()==null) || 
                (this.adType!=null && 
                  this.adType.equals(other.getAdType()))) && 
                ((this.destinationUrl==null && other.getDestinationUrl()==null) || 
                (this.destinationUrl!=null && 
                  this.destinationUrl.equals(other.getDestinationUrl()))) && 
                this.disapproved == other.isDisapproved() && 
                ((this.displayUrl==null && other.getDisplayUrl()==null) || 
                (this.displayUrl!=null && 
                  this.displayUrl.equals(other.getDisplayUrl()))) && 
                ((this.exemptionRequest==null && other.getExemptionRequest()==null) || 
                (this.exemptionRequest!=null && 
                  this.exemptionRequest.equals(other.getExemptionRequest()))) && 
                this.id == other.getId() && 
                ((this.status==null && other.getStatus()==null) || 
                (this.status!=null && 
                  this.status.equals(other.getStatus()))); 
            __equalsCalc = null; 
    }
            return _equals; 
        }
      

  4.   

    Java 深度探索者 QQ群:65670864