You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kathy Lo <ka...@gmail.com> on 2007/03/07 03:56:41 UTC

How to set global variable in Tomcat 5.5.17

Hi,

I setup Tomcat 5.5.17 in Linux Fedora Core 4 and develop a Web
Application under /webapps directory.

I have so many configuration files that need to be loaded into my web
application. These configuration files are in a self-defined format
and I wrote some Java classes to parse these configuration files and
save the parsing result in a linked list (java.util.List or
java.util.Map). These configuration files are static (not change).

In my web application, when a user session created, I call these Java
classes to parse these configuration files and save the linked lists
into the session. So, every user sessions contain the same set of
linked list and, as a result, it reads these files every time when
session created (so many I/O access, if many session created as the
same time, it will slow down the server).

Now, I want to save these linked lists as a global variables in Tomcat
so that each JSP and Servlet can access these global variables and
reduce I/O access and memory usage.

So, would you please tell me how to set global variables in Tomcat and
initialize them using the Java classes that I wrote.

Thanks

-- 
Kathy Lo

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to set global variable in Tomcat 5.5.17

Posted by Jacob Rhoden <ja...@rhoden.id.au>.
Instead of attaching information to a session context you can attach 
information to an application context, whats more, instead of loading 
the config each time a session is created, you can create what is called 
a "Lifecycle listener" which will load the configuraiton file once, when 
the application is loaded into the web server! Look up lifecycle 
listener in google. I can send sample code if you need it.

Best Regards,
Jacob

Kathy Lo wrote:
> Hi,
>
> I setup Tomcat 5.5.17 in Linux Fedora Core 4 and develop a Web
> Application under /webapps directory.
>
> I have so many configuration files that need to be loaded into my web
> application. These configuration files are in a self-defined format
> and I wrote some Java classes to parse these configuration files and
> save the parsing result in a linked list (java.util.List or
> java.util.Map). These configuration files are static (not change).
>
> In my web application, when a user session created, I call these Java
> classes to parse these configuration files and save the linked lists
> into the session. So, every user sessions contain the same set of
> linked list and, as a result, it reads these files every time when
> session created (so many I/O access, if many session created as the
> same time, it will slow down the server).
>
> Now, I want to save these linked lists as a global variables in Tomcat
> so that each JSP and Servlet can access these global variables and
> reduce I/O access and memory usage.
>
> So, would you please tell me how to set global variables in Tomcat and
> initialize them using the Java classes that I wrote.
>
> Thanks
>


-- 
__________________________________________
Jacob Rhoden - http://www.jacobrhoden.com/


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to set global variable in Tomcat 5.5.17

Posted by tang jie <cr...@gmail.com>.
Kathy Lo:
    I think you can use the interface
javax.servlet.ServletContextListener.In you implementation's method
contextInitialized(ServletContextEvent<file:///E:/java/api/j2eeri-1_4-doc-api/apidocs/javax/servlet/ServletContextEvent.html>
 sce),you can parse these configuration files and save the parsing result in
the application scope,for example:
sce.getServletContext().setAttribute("linkedlist",linkedlist);
then when you want to the linkedlist,you can get the ServletContext,and call
its getAttribute().

2007/3/7, Kathy Lo <ka...@gmail.com>:
>
> Hi,
>
> I setup Tomcat 5.5.17 in Linux Fedora Core 4 and develop a Web
> Application under /webapps directory.
>
> I have so many configuration files that need to be loaded into my web
> application. These configuration files are in a self-defined format
> and I wrote some Java classes to parse these configuration files and
> save the parsing result in a linked list (java.util.List or
> java.util.Map). These configuration files are static (not change).
>
> In my web application, when a user session created, I call these Java
> classes to parse these configuration files and save the linked lists
> into the session. So, every user sessions contain the same set of
> linked list and, as a result, it reads these files every time when
> session created (so many I/O access, if many session created as the
> same time, it will slow down the server).
>
> Now, I want to save these linked lists as a global variables in Tomcat
> so that each JSP and Servlet can access these global variables and
> reduce I/O access and memory usage.
>
> So, would you please tell me how to set global variables in Tomcat and
> initialize them using the Java classes that I wrote.
>
> Thanks
>
> --
> Kathy Lo
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>