Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ConnectionManager using singleton pattern

807589Nov 5 2008 — edited Nov 5 2008
Create a class called as ConnectionManager that manages a fixed array of Connection objects. The client programmer must not be able to explicitly creat Connection objects but can only get them via a static method in ConnectionManager. When the ConnectionManager runs out of objects, it returns null reference.



In constructor , crate array of size 10. and initialize with 10 connections. When client is asking for connection, return one conn and set it to null in array (using index)
When they return , add it back to array at any null locationÂ…

I think this is first thing comeing to mindf

So this is what i am trying with: first step,so far it is fine but first i want to know that do we need to send an int parameter in getConnection Method and how do we check if the connection is returned back to the pool
class Connection{
private static Connection[] con = new Connection[10];
private Connection(){
for(int i = 0; i < con.length ; i++)
con[i] = new Connection();
}
public static Connection getConnection(int i){
return con;
}

}

public class ConnectinManager{
public static void main(String[] args){
Connection con1 = Connection.getConnection(1);
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 3 2008
Added on Nov 5 2008
1 comment
152 views