Johnny -- A properly written static method would be completely stateless and could be executed from any number of threads simultaneously without issue. Think old style function calls in C where stuff is created on the stack and then popped off when execution finishes. The only hazard is if that static method tries to access an object that isn't thread-safe -- then you need sync blocks to protect the object.
--David Johnny Kewl wrote: > > ----- Original Message ----- From: "sinoea kaabi" <[EMAIL PROTECTED]> > To: "Tomcat Users List" <users@tomcat.apache.org> > Sent: Wednesday, September 17, 2008 12:48 PM > Subject: RE: Tomcat 5.5, JNDI Connection Pooling, Active connections > keep increasing.... > > > > Just a question here, > I am using a Data class to retrieve the datasource > > public class Data { > > /** > * Gets a [EMAIL PROTECTED] DataSource} for database connection usage. > * @return The datasource for database connection. > * @throws SQLException > */ > public static DataSource getDataSource() throws SQLException { > if (ds == null) { > DATASOURCE.info("DataSource is NULL "); > MANY_CONNECTIONS.info("DataSource is NULL "); > try { > final Context initContext = new InitialContext(); > ds = (BasicDataSource)initContext.lookup("java:/comp/env/jdbc/myDB"); > initContext.close(); > logDataSource(ds); > return ds; > } catch (final NamingException e) { > e.printStackTrace(); > throw new RuntimeException("Java naming exception when getting > connection from tomcat pool: " + e.getMessage()); > } > } else { > logDataSource(ds); > return ds; > } > } > > } > > ================================= > Sineoa, my feeling is dont use static, unless you really want it.... > in a multithreaded environment > It pumps all the threads thru one pipe... > > So yes I would *new* that as well... > > But note this is where you will better be server by a DBCP user... > because we dont use it... > > ie someone may say that declaring the Context as static is standard > practice and saves time... but I dont think so > > You cant really go wrong by making it new... but you can get nailed by > making it static ;) > > Have fun... > --------------------------------------------------------------------------- > > HARBOR : http://www.kewlstuff.co.za/index.htm > The most powerful application server on earth. > The only real POJO Application Server. > See it in Action : http://www.kewlstuff.co.za/cd_tut_swf/whatisejb1.htm > --------------------------------------------------------------------------- > > > > --------------------------------------------------------------------- > To start a new topic, e-mail: users@tomcat.apache.org > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]