Hello all,
I'm writing an application that connects to emailservers and fetches email from them to eventually put it in a Oracle database.
I'm doing this multi-threaded to compensate for the connection delays.
First, I made a single-threaded prototype, using a Transactional annotated method that synchronises the emailserver with the databaseserver.
This worked just fine.
Now I've tried my hand on multi-threading.
For every different emailserver, it starts a new Thread, in the run() method of that thread, I call the exact function used in the single-threaded prototype.
However, now I get the all known 'LazyInitializationException':
"Exception in thread "Thread-2" org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role"
The full stacktrace is below:
I allready tried using the "REQUIRES_NEW" propagation attribute, to create a new connection for every thread, without results.Code:Exception in thread "Thread-2" org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.webmailr.entity.server.MailDirectory.conversation, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:372) at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:119) at org.hibernate.collection.PersistentBag.size(PersistentBag.java:248) at com.webmailr.persistence.server.MailDirectoryDAOImpl.getLastRecievedMessage(MailDirectoryDAOImpl.java:22) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy24.getLastRecievedMessage(Unknown Source) at com.webmailr.business.mailcheck.fetcher.FolderFetcher.syncConversations(FolderFetcher.java:101) at com.webmailr.business.mailcheck.fetcher.FolderFetcher.fullSync(FolderFetcher.java:52) at com.webmailr.business.mailcheck.fetcher.FolderFetcher.fullSyncSubfolders(FolderFetcher.java:79) at com.webmailr.business.mailcheck.fetcher.FolderFetcher.fullSync(FolderFetcher.java:45) at com.webmailr.business.mailcheck.fetcher.ServerFetcher.fullSync(ServerFetcher.java:77) at com.webmailr.business.mailcheck.FetchManagerImpl.startSync(FetchManagerImpl.java:26) at com.webmailr.business.mailcheck.FetchThread.run(FetchThread.java:37)
Does anybody have experience in this field? Or do you know a quick solution to this problem?
Thanks,
Bart


Reply With Quote
