RE: [newbie] Connection Pooling
Michael, You certainly can write a connection factory class that provides getConnection type methods -- I do this all the time to abstract the different ways of doing connection pooling -- sometimes I am using DataSources -- other times not. However, you should just use a regular class for this that is *not* stored in the session -- perhaps even a singleton or utility class. Unless the connection pool configuration is user-specific I see no reason to store this object in the session. Let me know if this makes sense to you or if I do not fully understand your circumstances. -Original Message- From: Michal Postupalski [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 12, 2003 5:55 PM To: Struts Users Mailing List Subject: Re: [newbie] Connection Pooling On 2/12/2003 11:20 PM, Guido wrote: > IMHO, storing the connection in the session context is *never* a good > idea! > > 1. Session timeout uses to be too high if you must wait the session to > expire to close your connection (the user closes the browser...) > 2. You can kill your DB or you app server... And think about how many > connections would you need if your application has i.e. 3 hits/day? > You should use a connection pool. > > } Yes, it's a good idea. I use it sometimes but only when I have only one > } database's user. If You use more database's users to connect to database > } I wouldn't used connection pooling. > } > } plastic Ups..I didn't express corectly. I mean I keep in the session context not certain connection but object which provides connection pooling. I have i.e. static method getConnection() which returns next connection from the pool. plastic - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [newbie] Connection Pooling
Why wouldn't you use a simple update statement on the revised, validated data, rather than keeping the connection open for long? Z. > Folks, > > quite new to Struts and it's way to JPS-Action-etc. chaining I'd like to > know the following. Is their a way to keep open a certain connection to > a database between two actions, e.g. I have a EditGetAction where I > prepopulate a form, then show the jsp and make the user work and finally > after validation write the (maybe) changed fields back into the database > ??? > > Hope, this is not a absolutely stupid question ... > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [newbie] Connection Pooling
On 2/12/2003 11:20 PM, Guido wrote: IMHO, storing the connection in the session context is *never* a good idea! 1. Session timeout uses to be too high if you must wait the session to expire to close your connection (the user closes the browser...) 2. You can kill your DB or you app server... And think about how many connections would you need if your application has i.e. 3 hits/day? You should use a connection pool. > } Yes, it's a good idea. I use it sometimes but only when I have only one } database's user. If You use more database's users to connect to database } I wouldn't used connection pooling. } } plastic Ups..I didn't express corectly. I mean I keep in the session context not certain connection but object which provides connection pooling. I have i.e. static method getConnection() which returns next connection from the pool. plastic - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [newbie] Connection Pooling
Yes, so do I. :-) Marco -Original Message- From: Micha³ Postupalski [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 12, 2003 10:00 PM To: Struts Users Mailing List Subject: Re: [newbie] Connection Pooling On 2/12/2003 10:34 PM, Marco Tedone wrote: > You could write a PlugIn(new to Struts 1.1) to open a db connection > and store it in the session context. I would remember to close it in > the > destroy() method. > > Only an idea. Yes, it's a good idea. I use it sometimes but only when I have only one database's user. If You use more database's users to connect to database I wouldn't used connection pooling. plastic - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [newbie] Connection Pooling
100% agree. The only thing that should be placed in a session is user specific stuff. Connections should never be user specific, connections should be returned to the pool so other users can have them when they need it. The thing is that before such cool methodologies you had to buy 300-400 DB users for big apps, and db vendors made a killing that way, with the poolers and web connection pooling, now you can run a busy app on 5 user connections and keep the load light on the DB. Anyway implementing the PlugIn is easier than anything I've done so far in Struts. I just implemented it for my BaseOJBConnector class, it doesn't even have to be a servlet, and it opens up the db (the ojb pooler more specifically) and saves time on startup where users don't have to wait for the pooler to instantiate. Here is the code if someone wants to see an example: (If you want to do it with the commons pooler send me an email I'll send you the code, it's not very different) public class BaseOJBConnector implements PlugIn , Serializable { protected static Implementation odmg = null; protected static Database db = null; private static String ojbDBAlias = null; protected Log log = LogFactory.getFactory().getInstance( this.getClass().getName() ); /** * Default constructor, initializes the percistence layer. * @throws net.sfeir.exceptions.DataAccessException */ public BaseOJBConnector() throws DataAccessException { } /** * Opens the database and prepares it for transactions */ private void openDB( String DBC ) { if( DBC == null || DBC.length() < 1 ) DBC = "default"; // Get odmg facade instance odmg = OJB.getInstance(); db = odmg.newDatabase(); // Open database try { if( log.isDebugEnabled() ) log.debug( "Opening DB connection via OJB" ); db.open( DBC , Database.OPEN_READ_WRITE ); } catch( Exception ex ) { if( log.isFatalEnabled() ) log.fatal( "Something went very wrong in opening the DB connection" , ex ); ex.printStackTrace(); } } private void closeDB() { try { db.close(); } catch( ODMGException e ) { if( log.isFatalEnabled() ) log.fatal( "An exception occured during database closing" , e ); } } public void destroy() { closeDB(); } public void init( ActionServlet actionServlet , ModuleConfig moduleConfig ) throws ServletException { ojbDBAlias = actionServlet.getInitParameter( "database" ); openDB( ojbDBAlias ); } } On Wednesday, Feb 12, 2003, at 17:20 US/Eastern, Guido wrote: IMHO, storing the connection in the session context is *never* a good idea! 1. Session timeout uses to be too high if you must wait the session to expire to close your connection (the user closes the browser...) 2. You can kill your DB or you app server... And think about how many connections would you need if your application has i.e. 3 hits/day? You should use a connection pool. On Wed, 12 Feb 2003, [ISO-8859-2] Micha? Postupalski wrote: } On 2/12/2003 10:34 PM, Marco Tedone wrote: } > You could write a PlugIn(new to Struts 1.1) to open a db connection and } > store it in the session context. I would remember to close it in the } > destroy() method. } > } > Only an idea. } } Yes, it's a good idea. I use it sometimes but only when I have only one } database's user. If You use more database's users to connect to database } I wouldn't used connection pooling. } } plastic } } } - } To unsubscribe, e-mail: [EMAIL PROTECTED] } For additional commands, e-mail: [EMAIL PROTECTED] } --- - Guido Garcia Bernardo [EMAIL PROTECTED] [EMAIL PROTECTED] "stat rosa pristina nomine, nomina nuda tenemus." --- - http://members.ud.com/services/teams/team.htm?id=D8624419-BFB6-4772- A01A-0045631F979F - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] R -- Robert S. Sfeir Senior Java Engineer National Institutes of Health Center for Information Technology Department of Enterprise Custom Applications [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [newbie] Connection Pooling
IMHO, storing the connection in the session context is *never* a good idea! 1. Session timeout uses to be too high if you must wait the session to expire to close your connection (the user closes the browser...) 2. You can kill your DB or you app server... And think about how many connections would you need if your application has i.e. 3 hits/day? You should use a connection pool. On Wed, 12 Feb 2003, [ISO-8859-2] Micha? Postupalski wrote: } On 2/12/2003 10:34 PM, Marco Tedone wrote: } > You could write a PlugIn(new to Struts 1.1) to open a db connection and } > store it in the session context. I would remember to close it in the } > destroy() method. } > } > Only an idea. } } Yes, it's a good idea. I use it sometimes but only when I have only one } database's user. If You use more database's users to connect to database } I wouldn't used connection pooling. } } plastic } } } - } To unsubscribe, e-mail: [EMAIL PROTECTED] } For additional commands, e-mail: [EMAIL PROTECTED] } Guido Garcia Bernardo [EMAIL PROTECTED] [EMAIL PROTECTED] "stat rosa pristina nomine, nomina nuda tenemus." http://members.ud.com/services/teams/team.htm?id=D8624419-BFB6-4772-A01A-0045631F979F - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [newbie] Connection Pooling
On 2/12/2003 10:34 PM, Marco Tedone wrote: You could write a PlugIn(new to Struts 1.1) to open a db connection and store it in the session context. I would remember to close it in the destroy() method. Only an idea. Yes, it's a good idea. I use it sometimes but only when I have only one database's user. If You use more database's users to connect to database I wouldn't used connection pooling. plastic - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [newbie] Connection Pooling
It's possible but not a good idea, Struts or no Struts. Never, never, keep a connection open (especially in *session* scope!) while the user is picking her nose. Excuse me -- I mean "during user interaction". Enough simultaneous nose-pickers will take up all your available connections. Conversely, if the user waits too long the database may reclaim the connection and her changes go bye-bye. Also consider this: A session is long; say 5 minutes. The total time you use that connection is probably less than 2 seconds. Why keep it around when it can be used somewhere else? Return your connections to the pool as soon as you're done with them. -- los -Original Message- From: Marco Tedone [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 12, 2003 4:35 PM To: Struts-user-list Subject: RE: [newbie] Connection Pooling You could write a PlugIn(new to Struts 1.1) to open a db connection and store it in the session context. I would remember to close it in the destroy() method. Only an idea. Marco -Original Message- From: Andre Michel [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 12, 2003 8:53 PM To: Struts Users Mailing List Subject: [newbie] Connection Pooling Folks, quite new to Struts and it's way to JPS-Action-etc. chaining I'd like to know the following. Is their a way to keep open a certain connection to a database between two actions, e.g. I have a EditGetAction where I prepopulate a form, then show the jsp and make the user work and finally after validation write the (maybe) changed fields back into the database ??? Hope, this is not a absolutely stupid question ... - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [newbie] Connection Pooling
You can configure a DataSource in the struts-config.xml file that will return connections to you. You should not keep the connection open longer than needed and this means you shouldn't span action invocations. David Folks, quite new to Struts and it's way to JPS-Action-etc. chaining I'd like to know the following. Is their a way to keep open a certain connection to a database between two actions, e.g. I have a EditGetAction where I prepopulate a form, then show the jsp and make the user work and finally after validation write the (maybe) changed fields back into the database ??? Hope, this is not a absolutely stupid question ... _ Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [newbie] Connection Pooling
You could write a PlugIn(new to Struts 1.1) to open a db connection and store it in the session context. I would remember to close it in the destroy() method. Only an idea. Marco -Original Message- From: Andre Michel [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 12, 2003 8:53 PM To: Struts Users Mailing List Subject: [newbie] Connection Pooling Folks, quite new to Struts and it's way to JPS-Action-etc. chaining I'd like to know the following. Is their a way to keep open a certain connection to a database between two actions, e.g. I have a EditGetAction where I prepopulate a form, then show the jsp and make the user work and finally after validation write the (maybe) changed fields back into the database ??? Hope, this is not a absolutely stupid question ... - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [newbie] Connection Pooling
Andre ... this is not connection pooling -- but rather keeping a connection open. Yes it can be done ... however, HTTP is not a reliable connection and there is a good chance that your connection will get left open. However, it is time consuming to always have to open/close connections -- hence, the answer is connection pooling. If you are using a J2EE container that supports connection pooling (most do) you can use the connectors mechanisms for defining the connection pool. If not, you can use the Struts data-source elements which use the Commons DBCP package. -Original Message- From: Andre Michel [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 12, 2003 3:53 PM To: Struts Users Mailing List Subject: [newbie] Connection Pooling Folks, quite new to Struts and it's way to JPS-Action-etc. chaining I'd like to know the following. Is their a way to keep open a certain connection to a database between two actions, e.g. I have a EditGetAction where I prepopulate a form, then show the jsp and make the user work and finally after validation write the (maybe) changed fields back into the database ??? Hope, this is not a absolutely stupid question ... - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[newbie] Connection Pooling
Folks, quite new to Struts and it's way to JPS-Action-etc. chaining I'd like to know the following. Is their a way to keep open a certain connection to a database between two actions, e.g. I have a EditGetAction where I prepopulate a form, then show the jsp and make the user work and finally after validation write the (maybe) changed fields back into the database ??? Hope, this is not a absolutely stupid question ... - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]