This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Deadlock occur during fetching records in loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Deadlock occur during fetching records in loop" Watch "Deadlock occur during fetching records in loop" New topic
Author

Deadlock occur during fetching records in loop

Alka S.
Greenhorn

Joined: Nov 29, 2003
Posts: 26
Hi,
While fetching records in loop I get deadlock error. can we give setting for individual method of session bean for unlock? We are using EJB 2.0 and jboss as application server.
Thanks.
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3879
I don't think we have enough information on your design to offer you a solution. Can you describe your design in more detail and perhaps give some code?
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Alka S.
Greenhorn

Joined: Nov 29, 2003
Posts: 26
Code is as follows -
fetching data from entity bean in loop --
public Collection getFieldList(Integer userId, String rights, Integer aflId, Integer itemId, String itemType)
throws ItemNotFoundException, Exception
{
try
{
//Call fetchFields Method of Home
Collection col = field.fetchFields(aflId);
//Iterate through collection of primary keys of fields to get FieldVO Object
Iterator it = col.iterator();
while (it.hasNext())
{
Integer fieldId = (Integer) it.next();
Field indField = FieldBeanHome.findByPrimaryKey(fieldId);
FieldVO recvFieldVO = setBeanValues(indField);
String fieldType = recvFieldVO.getFieldType();
String data = "";

/////////////// data fetching from entity bean in loop ///////////////////
data = indField.fetchData(itemId, itemType, Constants.LATEST_VERSION);

recvFieldVO.setData(data);
//add fieldVO object to vector
vect.add(recvFieldVO);
}

return vect;
}
catch (Exception e)
{
}
}
----------------------------------------------------------------------
Error Messages is as follows -

Error:
Application deadlock detected: Two or more transactions contention.
com.powermanage.mcaccess.exception.ItemNotFoundException: Application deadlock detected: Two or more transactions contention.
at com.powermanage.mcaccess.ejb.common.Utils.getItemNotFoundException(Utils.java:233)
at com.powermanage.mcaccess.ejb.field.FieldServiceBean.fetchData(FieldServiceBean.java:276)
at sun.reflect.GeneratedMethodAccessor558.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:646)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:104)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:117)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:323)
at org.jboss.ejb.Container.invoke(Container.java:673)
at sun.reflect.GeneratedMethodAccessor488.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:101)
at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:90)
at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:45)
at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:100)
at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
at $Proxy622.fetchData(Unknown Source)
at com.powermanage.mcaccess.xml.XMLProcessor.fetchCustomData(XMLProcessor.java:620)
at com.powermanage.mcaccess.xml.XMLProcessor.processXML(XMLProcessor.java:168)
at com.powermanage.mcaccess.ejb.annotation.FormServiceBean.displayLayout(FormServiceBean.java:1243)
at sun.reflect.GeneratedMethodAccessor550.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:646)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:104)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:117)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:323)
at org.jboss.ejb.Container.invoke(Container.java:673)
at sun.reflect.GeneratedMethodAccessor488.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:101)
at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:90)
at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:45)
at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:100)
at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
at $Proxy646.displayLayout(Unknown Source)
at com.powermanage.mcaccess.portal.ViewFacilityAttributeAction.execute(ViewFacilityAttributeAction.java:306)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1480)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:506)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3879
Is this method part of a Session bean? If so, what's the transaction attribute on that method?
Kyle
Alka S.
Greenhorn

Joined: Nov 29, 2003
Posts: 26
Yes.
transaction attribute is 'required' as follows
ejb-jar.xml -
<container-transaction >
<method >
<ejb-name>FieldService</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Deadlock occur during fetching records in loop
 
Similar Threads
fetching records page/page
Trying to understand when to use 'finally' clause
deadlock
How To Avoid Deadlock?
Performance Issue - Constant Delay in ResultSet.next()