|
|
|
Re: Using Eclipselink with Streams in parallel gives NullPointerException [message #1828438 is a reply to message #1828386] |
Tue, 09 June 2020 15:42   |
Chris Delahunt Messages: 1389 Registered: July 2009 |
Senior Member |
|
|
I don't follow the person/family level synchronization issue. If the problem is accessing indirection within Person on multiple threads concurrently, synchronizing on person fixes that. Add accessors to wrap the getFamily method that your application uses, store the getFamily result in person (transient Family fetchedFamily; // for example), and just use synchronization on getFamily or on 'this' when calling getFamily if fetchedFamily is null. Multiple threads trying to get the family concurrently wait for one to fetch/build it before seeing it is there and just use it, and you avoid synchronization if it was already fetched.
As for prefetching - this depends on how you are looking at that object graph. In my current project, we have long lived caches, and the cost of fetching 'anything' during the processing is quite high compared to the processing itself. Having to sometimes delay to fetch a family is a non-starter for us; it needs dependable, predictable performance that necessitates building it upfront before starting. If you don't want the synchronization costs in your application, you might decouple the person->family relationship, and have it accessed separately from the object graph - something that fetches it from a separate cache (and EntityManager) when needed. Multiple concurrent threads looking up a person's family can then be handled how ever you need without adding synchronization or having concurrent access issues on the getFamily lazy indirection being triggered.
[Updated on: Tue, 09 June 2020 15:50] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02467 seconds