Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 92457 invoked from network); 1 Jul 2010 03:39:41 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 1 Jul 2010 03:39:41 -0000 Received: (qmail 537 invoked by uid 500); 1 Jul 2010 03:39:38 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 99990 invoked by uid 500); 1 Jul 2010 03:39:34 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 99976 invoked by uid 99); 1 Jul 2010 03:39:32 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Jul 2010 03:39:32 +0000 X-ASF-Spam-Status: No, hits=2.9 required=10.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [209.85.216.45] (HELO mail-qw0-f45.google.com) (209.85.216.45) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Jul 2010 03:39:24 +0000 Received: by qwg8 with SMTP id 8so489928qwg.18 for ; Wed, 30 Jun 2010 20:38:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.224.112.200 with SMTP id x8mr7071476qap.34.1277955493696; Wed, 30 Jun 2010 20:38:13 -0700 (PDT) Received: by 10.229.223.136 with HTTP; Wed, 30 Jun 2010 20:38:13 -0700 (PDT) In-Reply-To: <4C2BFB72.7030809@gmail.com> References: <4C296A8D.1020103@gmail.com> <4C2BFB72.7030809@gmail.com> Date: Wed, 30 Jun 2010 23:38:13 -0400 Message-ID: Subject: Re: "Application" vars - From: Shay Rojansky To: Tomcat Users List Content-Type: multipart/alternative; boundary=00c09f905ffb3d96c3048a4b33c1 X-Virus-Checked: Checked by ClamAV on apache.org --00c09f905ffb3d96c3048a4b33c1 Content-Type: text/plain; charset=ISO-8859-1 Hi Eric. On Wed, Jun 30, 2010 at 9:20 PM, Eric P wrote: > Shay, > > Forgive all potential newbness in my responses below. I'm still learning > this stuff. > > No worries for newbiness, your responses all make sense. > > Shay Rojansky wrote: > >> Hi Eric. >> >> Would making your servlet reload all application vars not be akin to >> simply >> reloading your servlet altogether, by changing context/init params in your >> web.xml or context.xml? >> >> > Do you mean "reloading your 'application' altogether"? If so wouldn't that > cause disruption to users currently on the app? This disruption is what I'd > like to avoid. So it makes sense to go into what "disruption" means. I'm not 100% sure about the following, it would be good if a tomcat heavyweight would confirm/refute what I say. When you initiate a webapp reload, Tomcat waits for requests that have already started processing to terminate. This ensures that people who accessed your app just before the webapp get a complete response. Once that's done, the application is reloaded and your servlets' init methods are called if necessary. During this time, incoming requests aren't denied, they are just paused until the reload is complete. So the only disruption people see is your application freezing up for the time it takes to reload (which is going to depend on what you your initialization consists of). No ugly server unavailable errors or anything of the sort. If you don't like the idea of your app freezing, think about this. Rereading environment params without reloading has its own risks, namely potential race conditions. Imagine you have 5 parameters, and requests are coming in as you are reading these in and initializing your webapp. A request might be handled while 2 params have been read, but 3 still contain the old values. If you start to think about locking/synchronization to solve this you're definitely better off just using Tomcat's reload mechanism. So my answer would be, trust Tomcat's reloading process unless you absolutely want to avoid your webapp freezing for the time it will take for it to init (this depends on the webapp). If you want to do your own "reloading", think long and hard about potential race conditions (which will occur in all except the simplest cases). Again, all this should probably be verified, you can set up very simple test cases with a JSP that sleeps, etc. > > If you really want to avoid an application reload, why not just have your >> app read its values from a properties config file instead of a DB? It >> would >> be much more lightweight and standard. >> >> > That's an idea. But wouldn't file I/O every time a servlet needs an > application value be way more expensive than storing settings in a record, > reading and setting them to the application scope once, and only resetting > these vars manually when needed? > I wasn't proposing to perform I/O and parse the properties file upon every request, simply to parse it once upon init and load it into application-scoped vars. This is exactly the same as what you were planning to do, except that instead of pulling the values from a DB record you pull them from a properties file. Note that using a property file will almost surely be faster (and not to mention simpler) than a database, as connecting to a database usually means network activity, authentication, etc. It would also make changing those values easier - editing a properties file is more straightforward than a database with its schema. But at the end of the day, it all depends on your app. If you already have everything in your DB and it makes sense to have those config values in there too, why not. > > Is this standard documented somewhere? > What exactly? :) > > Thanks... I appreciate the ideas. > Eric > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org > For additional commands, e-mail: users-help@tomcat.apache.org > > --00c09f905ffb3d96c3048a4b33c1--