Issue with dead threads
by Raymond Auge
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
17 years, 8 months
DB Connection Timeout
by J. Davison de St. Germain
Hi,
I've searched the web and read through a lot of documentation, but I
can't seem to find out how to do what I think should be a very simple
task. I want to specify how long hibernate will wait before it returns
from a DB connection attempt. I'm trying to test my code to ensure that
it behaves correctly when the DB is down. But testing takes forever
because every time I run the code, it takes about a minute to timeout
and throw the "no connection" exception. I know there has to be a way
(programmatically (and also via the config file)) to tell hibernate to
only wait, say, 5 seconds before throwing the exception. Any help you
could provide me would be greatly appreciated.
Sincerely,
Davison
--
-----------------------------------------------------------------------
- J. Davison de St. Germain dav(a)cs.utah.edu (801) 581-4078 -
- Chief Software Engineer http://www.cs.utah.edu/~dav -
- SCI Institute, SE C-SAFE University of Utah -
-----------------------------------------------------------------------
17 years, 9 months