i am trying to save all connection objects in hashmap in jdbc.but when ever i try to put connection object in map it does not store actual object. my code is like this
We can keep either of them as the Key in Map. As every connection instance is unique, that can be kept as key in the Map. I use Connection as key and the status of the connection as the value in my Connection Pool.
Originally posted by Jeanne Boyarsky: Gowher, I agree with Sarath. Just out of curiousity, why are you writing your own connection pool?
Also you probably want conPool.put("01" ,c); instead of conPool.put(c,"01");
That way you can look up the connection by the key ("01").
SCJP 1.4, SCDJWS , SCJA<br />I can do ALL things through CHRIST who strengthens me.
Why not implementing your connection pool as a queue.
The real connection pool should have some properties like, - shrink - extend
Now, how are you getting the connection from Map? By passing the connection object as a key? It means you already have the connection, you are not getting it from Map, right? So, what are you getting from the Map? Are you getting the status of that particular connection? Where are your connections reside?
Now, how are you getting the connection from Map? We call by DBConnectionPool.getConnection(). All the implementation is hided inside this method.
By passing the connection object as a key? No It means you already have the connection, you are not getting it from Map, right? So, what are you getting from the Map? Are you getting the status of that particular connection? Where are your connections reside?
We store the predefined amount of connection objects in a Map. We store the availability of the connection object as the Key(true/false). When the user requests for a new connection, We iterate over the map to get the first available connection and return the connection after changing its status(false). When connection is released from pool, we change its status to be available. (true).
hope I am clear now..
SCJP 1.4, SCDJWS , SCJA<br />I can do ALL things through CHRIST who strengthens me.
Sorry mate, I couldn't understand you. You said in your previous post that you are using connection object as key, and now you are saying that you are using availablity of connection as a key (true/false). These are two different things. As true/false is not unique, how can you use it as a key.
Iterate over a map until a free connection is found. Its not at all a good idea. Why not implement data structure like queue or stack. Queue would be better.