-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Thread issue with Sessions and Event Dispatch Thread
PostPosted: Mon Jun 26, 2006 5:05 am 
Newbie

Joined: Tue Feb 07, 2006 8:17 pm
Posts: 19
Hi,

I'm writing a Swing gui. We have a search screen that runs a query in hibernate. The search is paginated and we use a SwingWorker. The first chunk of data comes in and we give it to the gui to display. This involves a jump onto the Event Dispatch Thread (EDT). The gui may require associations to be lazy loaded. We now have two threads accessing the same session, the 'search thread' and the EDT.

I can't think of a solution to solve this that preserves :
* not locking the gui when we do a search.
* not explicitly hydrating all associations needed for the gui to display.

does anyone have any ideas on how to solve this?
are there thread safe session implementations that we could use? Does it make sense to write one?

thanks, Don
ps. the stacktraces I'm getting are :

java.util.ConcurrentModificationException
at org.apache.commons.collections.SequencedHashMap$OrderedIterator.next(SequencedHashMap.java:757)
at org.hibernate.engine.StatefulPersistenceContext.afterTransactionCompletion(StatefulPersistenceContext.java:289)
at org.hibernate.impl.SessionImpl.afterTransactionCompletion(SessionImpl.java:444)
at org.hibernate.jdbc.JDBCContext.afterNontransactionalQuery(JDBCContext.java:224)
at org.hibernate.impl.SessionImpl.afterOperation(SessionImpl.java:437)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1134)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:807)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:356)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:798)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:794)
at it.orchestrate.oep.territory.hibernate.TerritoryDAOImpl.findAccountsForTerritories(TerritoryDAOImpl.java:46)
at it.orchestrate.oep.territory.TerritoryManagerImpl.findAccountsForTerritories(TerritoryManagerImpl.java:207)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:292)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at it.orchestrate.oep.util.SessionInterceptor.invoke(SessionInterceptor.java:42)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.interceptor.AbstractTraceInterceptor.invoke(AbstractTraceInterceptor.java:97)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy10.findAccountsForTerritories(Unknown Source)
at it.orchestrate.oba.callplanning.LocationQuery.createCriteria(LocationQuery.java:67)
at it.orchestrate.oba.callplanning.LocationQuery.execute(LocationQuery.java:40)
at it.orchestrate.oba.searchview.SearchViewWorker.doInBackground(SearchViewWorker.java:75)
at it.orchestrate.oba.searchview.SearchViewWorker.doInBackground(SearchViewWorker.java:19)
at org.jdesktop.swingworker.SwingWorker$1.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
at java.util.concurrent.FutureTask.run(FutureTask.java:123)
at org.jdesktop.swingworker.SwingWorker.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Thread.java:595)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 26, 2006 11:04 am 
Newbie

Joined: Mon Jun 19, 2006 2:34 pm
Posts: 8
From your description I am guessing you are populating the data structure (probably a collection) with Hibernate that you are also trying to display in your GUI?

I will make a further guess and say you are probably trying to iterate over your collection while changing the collection which is where the ConcurrentModificationException is coming from.

You could fix this with synchronized blocks. However, because iterating over the collection could take be expensive depending on the size of the collection (and you wouldn't want to block the collection the whole time you are interating over it) you may be better off cloning the collection when you want to display it and iterate over the clone.

This is probably more of a general Swing question than a Hibernate question.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.