a122178
asked on
My Connection Pooling are not Persistant. It closes in at a several time. In Pure Java.
Hi All,
I have written my own connection pool. However, I run the application for one day, it closes automatically. I just wonder that is it a problem in my coding or in my database or tomcat setting.
Thank you so much.
I am using MYSQL and Java.
public class DBConnection extends DataConnection {
public DBConnection(WebSite website)
throws Exception {
open(website.databaseDrive r,website. databaseUr l,website. databaseUs ername,web site.datab asePasswor d);
}
}
public abstract class DataConnection {
public Connection innerConnection;
public boolean open(String driver,String url,String username,String password) throws Exception {
Class.forName(driver);
innerConnection = DriverManager.getConnectio n(url,user name,passw ord);
if(innerConnection==null)
return false;
return true;
}
public void close() {
try {
innerConnection.close();
System.out.println("Databa se Connection Closed Successfully..");
} catch(Exception e) {
}
}
public PreparedStatement prepareStatement(String sql) throws SQLException {
return innerConnection.prepareSta tement(sql );
}
protected void finalize() throws Throwable {
close();
super.finalize();
}
}
void loadDatabaseConfiguration( )
//throws WebSiteError
throws Exception {
try {
XMLParser parser = new XMLParser();
if(!parser.parseFile( getConfPath() + java.io.File.separator + "database.xml" )) {
throw new WebSiteError("Database information missing, Please setup database ","Click here to setup database","/conf/setup/");
}
databasexml = parser.parseFileXML( getConfPath() + java.io.File.separator + "database.xml" );
databaseDriver = parser.getValue("database/ driver");
databaseUrl = parser.getValue("database/ url");
// databaseDriver = "com.mysql.jdbc.Driver";
// databaseUrl = "jdbc:mysql://127.0.0.1:33 06/payment ";
databaseUsername = parser.getValue("database/ username") ;
databasePassword = parser.getValue("database/ password") ;
} catch (Exception e) {
throw e;
}
}
void loadPoolerConfiguration()
throws WebSiteError {
XMLParser parser = new XMLParser();
if(!parser.parseFile( getConfPath() + java.io.File.separator + "pooler.xml" )) {
throw new WebSiteError("Pooler information missing, Please setup database ","Click here to setup pooler","/conf/setup/");
}
//poolerSize = Integer.parseInt(parser.ge tValue("po oler/size" ));
}
private void loadPooler()
throws Exception {
try {
connections = new VectorEnum();
for ( int i=0; i<10; i++) {
DBConnection conn = new DBConnection(this);
connections.addElement(con n);
}
} catch(Exception e) {
throw e;
}
}
public synchronized DBConnection getConnection() {
return (DBConnection) connections.nextReset();
}
I have written my own connection pool. However, I run the application for one day, it closes automatically. I just wonder that is it a problem in my coding or in my database or tomcat setting.
Thank you so much.
I am using MYSQL and Java.
public class DBConnection extends DataConnection {
public DBConnection(WebSite website)
throws Exception {
open(website.databaseDrive
}
}
public abstract class DataConnection {
public Connection innerConnection;
public boolean open(String driver,String url,String username,String password) throws Exception {
Class.forName(driver);
innerConnection = DriverManager.getConnectio
if(innerConnection==null)
return false;
return true;
}
public void close() {
try {
innerConnection.close();
System.out.println("Databa
} catch(Exception e) {
}
}
public PreparedStatement prepareStatement(String sql) throws SQLException {
return innerConnection.prepareSta
}
protected void finalize() throws Throwable {
close();
super.finalize();
}
}
void loadDatabaseConfiguration(
//throws WebSiteError
throws Exception {
try {
XMLParser parser = new XMLParser();
if(!parser.parseFile( getConfPath() + java.io.File.separator + "database.xml" )) {
throw new WebSiteError("Database information missing, Please setup database ","Click here to setup database","/conf/setup/");
}
databasexml = parser.parseFileXML( getConfPath() + java.io.File.separator + "database.xml" );
databaseDriver = parser.getValue("database/
databaseUrl = parser.getValue("database/
// databaseDriver = "com.mysql.jdbc.Driver";
// databaseUrl = "jdbc:mysql://127.0.0.1:33
databaseUsername = parser.getValue("database/
databasePassword = parser.getValue("database/
} catch (Exception e) {
throw e;
}
}
void loadPoolerConfiguration()
throws WebSiteError {
XMLParser parser = new XMLParser();
if(!parser.parseFile( getConfPath() + java.io.File.separator + "pooler.xml" )) {
throw new WebSiteError("Pooler information missing, Please setup database ","Click here to setup pooler","/conf/setup/");
}
//poolerSize = Integer.parseInt(parser.ge
}
private void loadPooler()
throws Exception {
try {
connections = new VectorEnum();
for ( int i=0; i<10; i++) {
DBConnection conn = new DBConnection(this);
connections.addElement(con
}
} catch(Exception e) {
throw e;
}
}
public synchronized DBConnection getConnection() {
return (DBConnection) connections.nextReset();
}
sorry I can't understand what closes automatically the JVM?
Are you starting from the console? If so the process may be getting stopped. On Unix run with nohup in the background, on Windows run as a service
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
How does that explain the automatic closing of the application?
ASKER
I want to know the reason why the connection closes after a several time. Is there a default timeout period in the connection pool? The application stay forever.However, only the connection to the database closes.
>>The application stay forever.However, only the connection to the database closes.
In that case i misunderstood your question
In that case i misunderstood your question