[hibernate-users] Issue with dead threads

Raymond Auge rauge at liferay.com
Tue Mar 13 20:55:15 EDT 2007


Hello All,

I'm in need of some insight on a hibernate problem.

A little about the environment

- hibernate 3.2 CR2
- Spring 1.2.8

some background...

We have some logic which performs several operations on the db in a 
fairly random sequence... one of the operations is an SQL insert via 
hibernate

        *try* {
            session = openSession();

            *if* (draftAction.isNew()) {
                session.save(draftAction);
            }

            session.flush();
            draftAction.setNew(false);

            *return* draftAction;
        } *catch* (HibernateException he) {
            *throw* *new* SystemException(he);
        } *finally* {
        }


Now, since the sequence is random, we are expecting an exception to be 
thrown, because due to the behaviour of our business logic, the object 
we're trying ti insert may already exist in the db. So we are
anticipating it.

Here is the info log in the catch block wrapping the dao insert call:

22:19:41,634 INFO  [DraftUtil:581] com.sc.ScApplicationException: com.liferay.portal.SystemException: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
com.liferay.portal.SystemException: com.sc.ScApplicationException: com.liferay.portal.SystemException: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
        at com.sc.portlet.draft.service.spring.DraftActionLocalServiceUtil.addDraftAction(DraftActionLocalServiceUtil.java:14)
        at com.sc.portlet.draft.util.DraftUtil.doAutoDraft(DraftUtil.java:570)
        at com.sc.portlet.draft.util.DraftUtil.autoDraftRound(DraftUtil.java:495)
        at com.sc.portlet.fantasyteam.mlb.draft.action.JSONDraftedDataAction.getJSON



So, at a high level, imagine that there are 1000 choices to pick from, 
only one choice can be made, choices are made randomly, everyone's 
choice must be unique among the 1000, and there are 12 people making a 
choice in a random order, one after another. in a loop...

So the insert is both the selection action and the determination of 
whether the choice is already used up (when the exception is thrown, try 
again)...


The problem: randomly during execution (but very frequently) we are 
getting threads which become deadlocked while performing this operation 
and never return, and eventually all thread in the system are used up 
and the server become unresponsive.


Here is the hbm for one object:


	<*class* name="com.sc.portlet.draft.model.DraftAction" table="DraftAction">
		<cache usage="read-write" />
		<composite-id name="primaryKey" *class*="com.sc.portlet.draft.service.persistence.DraftActionPK">
			<key-property name="draftId" />
			<key-property name="fantasyTeamId" />
			<key-property name="round" />
		</composite-id>
		<property name="action" type="com.liferay.util.dao.hibernate.StringType" />
		<property name="range" type="com.liferay.util.dao.hibernate.StringType" />
		<property name="playerId" type="com.liferay.util.dao.hibernate.StringType" />
		<property name="createDate" />
	</*class*>


Here is the Spring config for the dao:

	<bean id="com.sc.portlet.draft.service.spring.DraftActionLocalService.professional" *class*="com.sc.portlet.draft.service.impl.DraftActionLocalServiceImpl" lazy-init="true" />
	<bean id="com.sc.portlet.draft.service.spring.DraftActionLocalService.transaction" *class*="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" lazy-init="true">
		<property name="transactionManager">
			<ref bean="liferayTransactionManager" />
		</property>
		<property name="target">
			<ref bean="com.sc.portlet.draft.service.spring.DraftActionLocalService.professional" />
		</property>
		<property name="transactionAttributes">
			<props>
				<prop key="*">PROPAGATION_REQUIRED</prop>
			</props>
		</property>
	</bean>
	<bean id="com.sc.portlet.draft.service.spring.DraftActionLocalServiceFactory" *class*="com.sc.portlet.draft.service.spring.DraftActionLocalServiceFactory" lazy-init="true">
		<property name="service">
			<ref bean="com.sc.portlet.draft.service.spring.DraftActionLocalService.transaction" />
		</property>
	</bean>


If anyone has any insight on why this might occur I would be very greatful.

Thank you,


Raymond Auge
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-users/attachments/20070313/3bcadec0/attachment.html 


More information about the hibernate-users mailing list