Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
JSP - A mailing list about Java Server Pages specification and reference
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
-none-

-none-

2007-09-04       - By Christopher Schultz

 Back
-- --BEGIN PGP SIGNED MESSAGE-- --
Hash: SHA1

Chad,

Chad Lung wrote:
> What I want to do is store information in a few static variables used
> in a servlet.  I'm looking for speed more than anything as the clients will
> be polling the server every 2-3 seconds.

I think what you really want is to store that information in the
"application" context, also known as the ServletContext. Any servlet can
get access to the ServletContext for any request.

You can use a ServletContextListener to listen for application startup
events to, say, load the data once from a database or flat file or whatever.

> What I'm curious about is how Tomcat
> handles static variables.

Tomcat does not support any special handling of static variables.

> Coming from ASP.NET experience I know that using
> static variables with IIS they are held in the app domain and the app domain
> can be reloaded by IIS for a number of reasons (config files changed, files
> changed, etc.)

This is sort of like the ServletContext, but in behavior only. Tomcat
discards the web application (context) when you redeploy, but the JVM
can hold onto references to the now-useless memory if you're not careful
about how you manage your memory. If you leave references to objects
from the old webapp around, you can cause the old webapp to stick around
in memory.

> This kinda makes using static variables in ASP.NET and IIS a
> bit tricky and unreliable.

Exactly. Same with Java and webapps.

> So the question I have is how does Tomcat handle
> static variables then?  When would they get reloaded/recycled, etc.?  I'm
> aware I could use something like memcached to mimic what I'm doing but again
> I'd rather stick to static variables if possible for the sake of simplicity.

Using the ServletContext to store information is easy, convenient, and
pretty safe. That's my recommendation. You could also take a look at the
build-in database that comes with the newer JVMs. I think there's an
in-memory implementation if you have complex data needs but still want
the speed of RAM.

- -chris
-- --BEGIN PGP SIGNATURE-- --
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG3id89CaO5/Lv0PARAvpjAJ98jJzq36367qFb/RaaGjDspFLpcACdH/NP
4FhYSHEYUx5HwggOBM2q/w4=
=wLEk
-- --END PGP SIGNATURE-- --

-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
To start a new topic, e-mail: users@(protected)
To unsubscribe, e-mail: users-unsubscribe@(protected)
For additional commands, e-mail: users-help@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.