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.