Thanks for some input. Hmm, perhaps i'm in over my head conceptually.
Quote:
Why* do other threads have a reference to the internal transaction?
Maybe it's best answered with a scenario. Let's say a transaction that needs to be done for the sake of argument a "bank deposit". Sometimes we fire and wait, and other times we fire, and come back the next day to get the answer. The answer, for example, being the resulting balance (to keep it simple).
So we do, in fact, have a pool of workers that pull transactions off our internal queue and do what is necessary to "deposit" and enter the "balance". For those Servlets that fire and forget, there's no potential conflict.
For those servlets that fire and wait, they are sent a notification. When the notification is complete, the object is returned to the client. Yes, we could make changes to the application so that notification is sent, and the object is reloaded ... however this suggested solution works okay when, in fact, we "are" persisting. To make matters more interesting for us, we have some business objects that are purely transient, that a worker still needs to process, and return notification that the object has been updated (in memory). So, in this case, there is no place for the notified thread to "reload" a transaction from. It really "needs" to maintain a reference. well, i'll look into that solution, i suppose.
However, this is the simplest scenario. The suggestions that i'm getting are rather Hibernate/DB centric (as i would expect). In point of fact, workers processing the transaction are not necessarily the only objects in our application that might want to make a change to an object at some time or other. These workers are in place to process transactions, not necessarily to persist them (although maybe that is what you'r suggesting i add)
To make this more interesting, these transactions that we have are generally part of a collection of a larger "Batch" object. This 'Batch' object also is notified when all of it's transactions are complete so that it knows when "it's" complete. So i'm guessing that it will want to reload these transactions from a persistant store on notification as well?
This isn't hypothetical, the apps and business objects have been in place for over a year now.
Quote:
The bottom line question is, why do you think you need to have a single VM-level shared multithreaded cache of persistent objects? Do you KNOW you need it?
No i don't know that i need it, and hope i do not. I'm starting to get an understanding of the problem through your post. Thing is that our business objects may or may not be living in a "persistant" world, and when they are not, the only way to pass them around is by reference.
My other concern is that while it's all well in good to "say" that when an object is placed on a queue, insure that whoever placed it there get's a fresh copy and does not continue to use it's reference to it. I suppose i could document in capital letters somewhere that all objects that are placed on a queue should be dereferenced.
But other than never passing a reference to an object from one thread to another (gavin's suggestion), i don't know of any easy way to insure that any holders of a reference to this object get a fresh copy because it's just been persisted.
I suppose i could build in some sort of notification right into the business object.
okay, like i said, maybe i'm asking too much or am over my head. Or maybe i don't even have the problem i think i have.
Looks like i need to rescrew my head on and take a different view of this problem.
The notion that an object shouldn't be sitting on 2 different threads if it has the possibility of being persistant never ever occured to me. maybe it should have. Our current deployed archictecture fundamentally works on the notion that all transactions are placed in a queue and workers pick them up. Some times they are waited for, sometimes they are not. Sometimes they are persisted sometimes they are not. So keeping a reference to it is something i can't turn my back on...
i appreciate your indulgence and help. Looks like i got a lot more to analyze and/or prototyping to do.
oh, in terms of benchmarks. Reading in one of our transactions is really not that expensive. In the past, it appears that the round trip to Oracle took more time than anything else. Maybe it's the driver, i don't know. But if somebody is waiting on "one" transaction it doesn't take long. 300 milliseconds on average, most of which is wrapped in overhead.
On the other hand, when our customer is waiting to see a whole batch of say, only 300 transactions (a small one), well then we need to insure that we minimize round trips to oracle. Unfortunately our Batches, have Requests, which in turn have Transactions. I was able to optimize this in a previous home brew, but am hoping that hibernate will handle it okay. If not, i'm confident i can do something to help it.
thanks again