EveryBody knows the concept of Connection Pooling and why it is used and blah blah.. but my question is that why can't we make a Singleton class of making a Connection and all other classes using it .. Many people talk about memory and security issues ..If my aaplication don't have any issues with that ,can i go for a singleton Connection class and if not what are the disadvantages and why connection pooling concept outscore the singleton way of doing
If you used a singleton to provide a JDBC Connection you would effectively be serializing access to the database, because you'd have one and only one Connection for all your code to use. RDBMS's are multiuser by design, so why you would want to ignore this feature and make it a single user database I don't know.
I don't really see how Connection Pooling and "memory and security issues" are related. What memory and security features do you believe Connection Pooling gives you?
I know RDBMS are multiuser by design but if my application is small don't you think it is better to work with a single connection and not going for a connection pool which byitself makes the server slow and opening and closing the connection.my question is why people are not opting for single connection approach and whate are its disadvantages in doing and using it.and as for the "memory and security" issues these pints are always mentioned as the advantage Connection Pool has and i am not making out of my own i was only discusiing why..
Suppose your application has a method which includes an JDBC operation. This method gets the connection from your singleton and starts this opreration. This method doesn't complete till the JDBC operation has finished. Suppose that operation is a select from a table with half a million rows (spurious example I know, but done to illustrate a point, I hope you understand). No other method in your application can use the connection till this method has finished. Now I don't suppose that is a problem if your application is a single threaded system. I also think you'd be exposing your application to network issues. Suppose the connection fails. If you established it through a Singleton, the only way to reestablish the connection is to restart the application.
OK I'll concede Connection Pooling may reduce memory use, since Connection Pooling will probably create fewer Connection objects than a multithreaded application which explicitly creates a Connection every time it needs to use one (as a result of Connection reuse). I still dont see the link between Connection Pooling and security though. In fact Connection reuse will possibly expose your application to security problems, since a shared resource will not be tied to a specific authenticated process. (i.e. your using something like JAAS or J2 Security. One process which has permission to open a connection does, then another which doesn't comes along and reuses the already open connection).
I'll also concede that Connection Pooling is overkill for very small applications. If your application is simple then I'd just let let it manage Connections itself. Still, a single Connection object for the whole application is going to cause problems.
Joined: Oct 28, 2004
Thanks Paul..I got it cleared but still i think there are many issues which can be debated over this topic