• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

using a datasource

 
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to integrate this forum in another application under the same context (servlet context) and database maybe. So i would like to re-use a datasource and dbcp connection pooling.

I implemented DBConnection to use the datasource in jforum in this manner but after some times the application go in deadlock, becuase i make a request with browser but i never get answer:
the source code is that:

public class DatasourcePooledConnection extends DBConnection {
private static DatasourcePooledConnection pool;
private static DataSource datasource;
private static final Logger logger = Logger.getLogger(DatasourcePooledConnection.class);

private static final boolean debug = false;
/**
* Private constructor that loads the driver and set the configuration from
* the properties file. It will also initialize the Database driver.
*
* @param dbConfigFile The full path plus the filename to the file which contains database specifc parameters
* @throws IOException
* @throws Exception
*/
public DatasourcePooledConnection() {
}

/**
* Inits ConnectionPool.
* If the pool was already initialized, this action will take no effect.
*
* @throws Exception
*/
public void init() throws Exception {
SystemGlobals.loadAdditionalDefaults(SystemGlobals.getValue(ConfigKeys.DATABASE_DRIVER_CONFIG));
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");

datasource = (DataSource) envCtx.lookup("jdbc/MyDataSource");
this.isDatabaseUp = true;
} catch (NamingException ne) {
ne.printStackTrace();
}

this.enableConnectionPinging();
}

/**
* Gets a connection to the database.


*
* So you need to release it, after use. It will not be a huge problem if you do not
* release it, but this way you will get a better performance.


* Thread safe.
*
* @return <code>Connection</code> object
* @throws java.sql.SQLException
*/
public synchronized Connection getConnection() throws SQLException {
return datasource.getConnection();
}

private void pingConnections() {
}

public void enableConnectionPinging() {
}

/**
* @see net.jforum.DBConnection#realReleaseAllConnections()
*/
public void realReleaseAllConnections() throws Exception {
}

/**
* Releases a connection, making it available to the pool once more.
*
* @param conn <code>Connection</code> object to release
* @throws java.sql.SQLException
*/
public void releaseConnection(Connection conn) throws SQLException {
if (conn == null) {
if (debug) {
logger.warn("Cannot release a NULL connection!");
}

return;
}
}

/**
* Returns the status
*
* @return The status
*/
public synchronized String getStatus() {
return "not implemented";
}
}


[originally posted on jforum.net by agori]

 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No idea :roll:

The application just stop working? no exception at all?

Rafael
[originally posted on jforum.net by Rafael Steil]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes no exception!

You can see i didn't implement method like

this.enableConnectionPinging();
private void pingConnections()
public void enableConnectionPinging()
public void realReleaseAllConnections()

I don't think releaseAllConnections is a problem.
But maybe should I implement the others?



[originally posted on jforum.net by agori]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, aren't you suppose to release the connection at releaseConnection()? I see that your code just check for null, but don't release it..

Release allConnections() is not necessary, in your case, since the method is called when the container is going down.

Rafael
[originally posted on jforum.net by Rafael Steil]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes sure! I forgot it!

[originally posted on jforum.net by agori]
 
We don't have time for this. We've gotta save the moon! Or check this out:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic