omar al kababji wrote:hehe yes but instead of accessing only one DAO you access n DAO's anyway i will be testing the idea in the web applications i will developer these days ;)
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
omar al kababji wrote:what i meant is that instead to make all your calls to only one DAO with its method synchronized
so that performance would increase and memory footprint would decrease. eliminating unnecessary operations of object initialization and garbaging those objects.
mmm may be you are right, but sometimes saving memory as much as possible is not a bad thing to do. don't you think so ?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
mihira
Why would you need to synchronize those methods?
First, often saving memory actually is in conflict with improving performance. Second, improving performance and saving memory need to be balanced with at least implementing functionality and having a simple, maintainable system.
Still then, I don't see any benefit added by synchronization. It would only slow down things. A decent DB itself can perfectly handle concurrent queries.omar al kababji wrote:in my case because the DAO's will be shared by all the parts of the application so synchronization will be needed in order to prevent concurrency problems. in a normal case there would be no problem for synchronization.
Still, your concern makes not much sense. A simple Java class like a DAO class is not an expensive resource as a database connection. Creating may cost 1ms. Garbaging may cost 1ms. Maybe less. Not worth a pool. Connecting may cost several hundred ms. There is fairly limited amount of connections available. That is certainly worth a pool.Yes you are right but when we talk about DAO's we are talking about objects that connect to a DB connection, and those connections are limited so why creating 10000 DAO's when you only have 20 connections ? at the end there will be only 20 DAO's capable of using those 20 connections at a time, so the rest of DAO's we sit there fighting for a free connection, so why even creating them ? and why wasting CPU time creating and then garbage them. may be its not that time consuming but for me every piece of byte saved is good, (Von Neumann would be happy to hear that
)
I agree on a bit of more complexity but once is done it would be easy to reuse it in other projects, for the possible bugs I have implemented the code in such a way that if any exception could be caused by using the Pool of DAO's it will fallback to the ordinary way which is create a new DAO and send it back, i put an assertion on that piece of code because i have a strong bielive that it will never happens, (never say never anyway ;)). In addition there is a configuration that could turn off the pool where the Pool Manager would be sending back normal DAO's as if they where created manually using the constructor.
Consider Paul's rocket mass heater. |