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.  [ 3 posts ] 
Author Message
 Post subject: Multi-threading errors.
PostPosted: Sun Apr 12, 2009 11:31 pm 
Newbie

Joined: Sun Apr 05, 2009 12:15 am
Posts: 7
I wrote a simple application to parse an rss feed and store it into database. I am using Hibernate mapping to store the rss data objects into into mysql DB.

The application worked fine until I changed the application to use Threads. After implementing threads I have started getting the following errors:

[java] Exception in thread "ReaderThread Number4" java.lang.NullPointerException
[java] 1119438564
[java] at org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge.nextTimestamp(RegionFactoryCacheProviderBridge.java:85)
[java] 1119438564
[java] at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:557)
[java] Title=Coffee Table (Trussville) $50
[java] at org.hibernate.context.ThreadLocalSessionContext.buildOrObtainSession(ThreadLocalSessionContext.java:142)
[java] 1119487285
[java] at org.hibernate.context.ThreadLocalSessionContext.currentSession(ThreadLocalSessionContext.java:103)
[java] 1119487285
[java] at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:574)
[java] at com.closebyme.feeds.reader.CraigslistFeed.createPosting(Unknown Source)
[java] at com.closebyme.feeds.reader.CraigslistFeed.processFeed(Unknown Source)
[java] at com.closebyme.craigslist.manager.CraigslistManager$ReaderThread.run(Unknown Source)
[java] at java.lang.Thread.run(Thread.java:595)
[java] Exception in thread "ReaderThread Number1" java.lang.NullPointerException
[java] at org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge.nextTimestamp(RegionFactoryCacheProviderBridge.java:85)
[java] at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:557)
[java] at org.hibernate.context.ThreadLocalSessionContext.buildOrObtainSession(ThreadLocalSessionContext.java:142)
[java] at org.hibernate.context.ThreadLocalSessionContext.currentSession(ThreadLocalSessionContext.java:103)
[java] at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:574)


I have been trying to find good examples on implementing multi-threaded application using hibernate but I haven't been able to find good examples. I am not sure if there are specific caveats or guidelines for implementing multithreaded apps with hibernate.



Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 13, 2009 5:38 am 
Beginner
Beginner

Joined: Wed Sep 21, 2005 8:18 am
Posts: 31
How you have implemented multithreaded. Send me your code then i will be able to help you.

_________________
amer sohail


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 13, 2009 6:06 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
getCurrentSession gets the Session for the current thread; when using multiple threads you should make sure that each thread is opening it's own Session, don't share them. Also it's not a good idea to transfer attached objects to another thread, make sure you detach your object graph before handing it over to another thread.

If you need to "preload" some information for other threads make sure to configure proper second level cache, if the preloading thread is making the same queries that the other thread is going to do you won't hit the database a second time.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.