Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Tomcat Users »

RE: Accessing objects with any servlets, where the object is already pre-created

Peter Guyatt

2003-10-07

Replies:

Hi there,

Use somthing like this

public calss stringHolder {

 private static stringHolder instance;
 private Vector v;

 public static stringHolder Instance() {
   if (instance == null) {
     instance = new stringHolder();
   }
   return instance;
 }

 private stringHolder() {
   v = new Vector();
 }

 public addString (String s) {
   v.add(s);
 }

 public Vector getStrings() {
   return v;
 }

}

There now all you have to do is call the Instance() method to get a handle
on the class.

There will only ever be one instance so it can be used between multiple
Servlets

Hope this helps

Thanks

Pete

-----Original Message-----
From: zeallousbigpond.net.au [mailto:zeallous@(protected)]
Sent: 07 October 2003 11:43
To: tomcat-user@(protected)
Cc: zeallous@(protected)
Subject: Accessing objects with any servlets, where the object is
already pre-created



Hi guys!

Is it possible to create a bunch of objects, put them aside, and Servlets
can just access them any time without recreating those objects or having to
pass them around??

say, Vector s = a very large vector of Strings that will appear in many
servlets, but now I don't want to have to create them in each servlet, I
want to have them pre-created somewhere, and servlets will go grab them when
they need that Vector of Strings.

Thanks!

Anson



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)


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