[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5759) ehcache causes deadlock

senthil (JIRA) noreply at atlassian.com
Sun Nov 28 18:01:13 EST 2010


ehcache causes deadlock
-----------------------

                 Key: HHH-5759
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5759
             Project: Hibernate Core
          Issue Type: Bug
          Components: caching (L2)
    Affects Versions: 3.5.2
         Environment: ehcache 1.2.0, oracle 11g, weblogic 10 and hibernate 3.5.2
            Reporter: senthil
            Priority: Critical


We have following mapping in our model,

<class name="Employee" table="employee">
          <cache usage="read-only" name="basic_cache" />  
             <id name="id" column="news_id">
                     <generator class="native"/>
              </id>
          
             <many-to-one name="person" class="Person" column="person_id" not-null="true" />   
          
      </class>
    
    <class name="Person" table="Person">
       <cache usage="read-only" name="basic_cache" />  
         <id name="id" column="person_id" />
         <property name="firstName" column="person_firstName" />   
         <property name="secondName" column="person_secondName" />
          <set name="PhoneNumbers" table="PHONE" cascade="none" order-by="phoneNumber asc">
                <cache usage="read-only" name="basic_cache" />        
				<key column="phone_id" />            
			<one-to-many column="PHONE_ID" class="Phone" />         
		   </set>
      </class>
    
		<class name="Phone" table="PHONE">      
			<cache usage="read-only" name="basic_cache" />  
			<composite-id>
				<key-property name="number"/>
				<key-many-to-one name="addressDetails" class="Address" >
				<column name="addressId" />
				</key-many-to-one>
			</composite-id>
			<property name="phoneType" type="string" length="10" column="PHONE_TYPE" />        
			<property name="phoneNumber" type="string" length="15" column="PHONE_NUMBER" />    
		</class> 

    <class name="Address" table="Address">
       <cache usage="read-only" name="basic_cache" />  
         <id name="id" column="address_id"/>
         <property name="street" />   
         <property name="houseNumber" />
      </class>


The POJO object is normal as depends on the property in the model, 
The below one is the basic listing of the classes, please bear for that if you find any syntax error,
public class Person {
 Long id;
 // here all the properties are declared with getter and setter but there is no equals and hashcode 
}



public class Phone implements Serializable {
 Long number;
 Address addressDetails;
 // the remaining properties are declared as normal
 public boolean equals(Object obj) {
   Phone newPhone = (Phone) obj;
   return EqualsHelper.equals(this.number, newPhone.getNumber()) && EqualsHelper.equals(addressDetails, newPhone.getAddressDetails());
 }
 
 public int hashCode() {
  int result = 31;
  if(number == null) {
    result = result * super.hashCode();
  } else {
   result = result * number.hashCode();
  }
  if(addressDetails!=null) {
   result = result * addressDetails.hashCode();
  }
  return result; 
 }
 
}

public class Address implements Serializable {
 Long id;
 // the remaining properties declared as normal
 public boolean equals(Object obj) {
   Address address = (Address) obj;
   return EqualsHelper.equals(this.id, address.getId());
 }
 
 public int hashCode() {
  int result = 31;
  if(id == null) {
    result = result * super.hashCode();
  } else {
   result = result * id.hashCode();
  }
  return result; 
 }
 
}

public class BatchLoad {
   public static void main(String args[]) {
    for(;;) {
    //fetch all persons in the person table and run that in a separate thread,
    // I mean for eg. run 10000 persons into 12 threads 
    }
    
    public class BatchRun implements Runnable {
       public void run() {
          
          for(int empNumberstartswith = 100; empNumberStartWith <= 800; empNumberstartswith++) {
              Session session = SessionFactory.getCurrentSession();
              Person p = (Person)session.get(Person.class, new Long(empNumberStartswith));
              // rest of the operations by accessing p
          }
       }
    }

   } 
}

Here, the problem is that loading and processing of Person works fine with 1 thread or sometimes even with 8 threads. But, when the number of threads are more than 8 then there is java level deadlock happens in loading Person and accessing Phone and subject.
The main point is that we don't have any synchronized block in our code. In ehcache the ReadWriteEntrantLock with Cache.put and ReadEntrantLock with Cache.get is causing the deadlock. It really made our life frustrating as this is now also happening in our online server as well, ie. with 15 or 20 users no issues if it crosses 20 then no more request accepted from Application server the ehcache makes every subsequent to deadlock state.

If its needed I can place the whole stack trace. Its mainly happening while writing into cache and reading into cache value though we only use read-only cache.

Any explanation would be very helpful or if you think our mapping is issue then please point it.

Thank you very much in advance!

Regards,
Senthil



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list