Hi,
I could need a little clarification on the area of entities and threads. I'm experimenting with a desktop application, which purpose is to manage my personal DVD collection. I'm keeping things simple, and i do not use any fancy transfer objects or the like.
Now, i've got a DvdServices class which returns a collection of Dvd instances - each representing a DVD in my collection. To be a little more specific, the DvdServices class manages the transactions and sessions, but the DvdDao class is the place where the actual database querying is going on. This collection is handed over to my GUI, which displays the DVD's in a list.
One feature of this software is to automatically find ratings for each DVD by querying an external service. This means that for each Dvd instance, i need to download one or more available ratings from the external service, update the Dvd instance with the rating and persist all changes. However, as with any GUI application, i need to display some progress details. However, updating the progress bar does not work very well if i do the external DVD rating querying on the event dispatch thread. So, i will to do both external querying and database operations on another thread.
That involves handing the Dvd instances over to another thread, retrieving ratings and updating those objects there, and getting them back in a new state. I've recently read "Concurrency In Practice" by Goetz, and one of the main things i got from that book is that there are a LOT of potential pitfalls lying here. However, what i would do is to synchronize all accessors and mutators on the object to ensure thread visbility. There will never be any potential issues with two different processes updating the objects at the same time. The only issue will be to maintain thread visibility, so that the state of the objects are properly maintained.
I would LOVE to hear any thoughts on this, and not least if it makes sense and adheres to what one could call "best practices". I'm doing this project mostly to learn how to do things right, so if anyone has been through anything similar - then i'd be really happy to hear how you did it.
Thanks!
|