Forums Register Login

Using an existing constructor question

+Pie Number of slices to send: Send
Hello All,

I am trying to write a code to iterate through a properties file to get database connectivity info and check the connectivity of multiple databases. I am also doing predetermined number of attempts in case of failures to the database connectivity. I am using a Thread object's sleep method for the delay of these attempts. The existing codes uses a constructor for reading a properties file from a util.Properties object. This constructor is widely used to instantiate and use it's method to create a database connection object for a single database. But my coding effort involves multiple database access. Without affecting the existing constructor what would be the best possible solution to achieve what I am trying to do. This is what I had which somewhat affects the existing class of the constructor -

public class DBConn {

protected Connection connection = null;

private DBConn() {}

...

// This is the existing constructor. Taken out the common codes within it
// and have added it in the new dbConnect method
public DBConn(String dbInstance) throws SQLException, IOException {

// Create Properties object
Configuration aConfiguration = new Configuration();

// Now calling the method to do the actual db connection
dbConnect(dbInstance, aConfiguration);
}

public DBConn(int intMaxAttempt) throws SQLException, IOException {

// Create a Configuration object
Configuration aConfiguration = new Configuration();

Thread thread = new Thread();

// Read the Configuration.properties file and retrieve all
// valid dbInstance related to the db.pool key.
ArrayList alKeys = aConfiguration.getParamArrayList("db.pool");

// Flag and counter to control looping
boolean boolConnFlag = false;
int counter = 0;

// Now iterating thru the array list
Iterator iterator = alKeys.iterator();
while (iterator.hasNext()) {

String instanceCode = (String) iterator.next();
// Now loop thru until a successful db connection is
// established or exceeds the attempts counter
while ( (boolConnFlag == false) && (counter <= intMaxAttempt))
{

// Now calling the method to do the actual db connection
boolConnFlag = dbConnect(instanceCode, aConfiguration);
LOG.info("1 boolConnFlag -> " + boolConnFlag);
// increment the counter
// For testing purpose set boolConnFlag to false
//boolConnFlag = false;
counter++;
LOG.info("2 boolConnFlag -> " + boolConnFlag);
LOG.info("counter -> " + counter);

// Now add delay before entering the loop again
// Arbitarily chosen 300 milliseconds. Could be any valu
e
+Pie Number of slices to send: Send
Sorry, hit the wrong key before finishing my posting. Rewriting it again.

Hello All,

I am trying to write a code to iterate through a properties file to get database connectivity info and check the connectivity of multiple databases and log the information into a log file using Log4j. I am also doing predetermined number of attempts in case of failures to the database connectivity. I am using a Thread object's sleep method for the delay of these attempts. The existing codes uses a constructor for reading a properties file from a util.Properties object. This constructor is widely used to instantiate and use it's method to create a database connection object for a single database instance. But my coding effort involves multiple database access. Without affecting the existing constructor what would be the best possible solution to achieve what I am trying to do? i am using JDK 1.3. This is some of what I have which somewhat affects the existing class of the constructor -


Would appreciate for your expert suggestion.

Thanks!

[edit]Add code tags. CR[/edit]
[ June 20, 2008: Message edited by: Campbell Ritchie ]
+Pie Number of slices to send: Send
Not a beginner's question. Shall move this thread.

Don't call a public non-final method from the constructor. Please use CODE tags, otherwise we only see an illegible mass of code. Without knowing what you have in your dbConnect() method, I don't think we can make any sensible comments.
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1083 times.
Similar Threads
Servlet Login
java.rmi.RemoteException: NullPointerException
isNew() method
does gc still have a chance to do its job if i kill the java process
database connections in threaded app
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:02:07.