-->
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.  [ 1 post ] 
Author Message
 Post subject: Objects with proxies used in threads : detach / attach
PostPosted: Wed Aug 04, 2010 12:43 pm 
Newbie

Joined: Wed Aug 04, 2010 11:50 am
Posts: 1
Hello to all,
Here is a problem, that may be quite common, so if somebody has any clue .....
I have a process that collects a list of objects with many-to-one relationship, and then process them one by one.
The pseudo code looks like
Code:
List<anObject> theList = criteria.list();
for (anObject ob : thList)
{
    doSomething(ob);
}


I would like to accelerate the process with threads like this :
Code:
List<anObject> theList = criteria.list();
List<resultObject> resultList = new ArrayList();
ExecutorService pool = Executors.newFixedThreadPool(5);
for (anObject ob : thList)
{
    doSomethingCallable = new doSomethingCallable(ob);
    pool.sumbit(doSomethingCallable );
}
for( resultObject res : resultList )
{
   res.get();
   .....
}
pool.shutdown();


And it happens, what is described in the doc, when proxies are fired in the doSomethingCallable, on anObject members, they are refering to the top level session.
Unfortunately this happens in // an the top session that is not thread safe returns errors (closed set, ....).

Up to now, this is fairly understandable.
Then i tried to detach the objects of the theList and to re-attach them to a "local session" (hSessionLocal) initiated in each doSomethingCallable thread.

To do that i ve simply closed the top level session, and in each doSomethingCallable called, issued a hSessionLocal.update(ob);

This is where things get wrong : even if the top level proxy are then bound to the new thread local session (hSessionLocal), deeper objects proxies are bound to ... nothing.

I ve tried to play around with the cascade attribute and with other methods (lock / merge) ... without success.

So the question is the following : is there a generic way to attach a graph of objects : should i walk the whole graph and issue a hsessionLocal.update(node) for each node ????
( PS reloading the object in each thread, does not solve the pb, since, if technically speaking there is no more error, the whole process is longer than in mono thread :-( )

By advance thank you for any comment.


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

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.