----------------------------------------------------
Please read the FAQ at <http://java.apache.org/faq/>
It does have a search feature!

We cannot guess what you are trying to do:
#1. Include version numbers for all software.
#2. Include relevant configuration settings.
#3. Include full descriptions of the problem.

Got Linux? Seeing lots of java processes?
<http://java.apache.org/faq/?file=274>
----------------------------------------------------

I use the first method you give rather extensively. The basic steps are:

// 1. Define a member variable of your global class which is an instance
of the class:
public class GlobalObject {
  private static GlobalObject _global;

  // 2. Make the constructor private so that no one can instantiate us.
  private GlobalObject() {
    //...
  }

  // 3. Define a method which instantiates a GlobalObject if
necessary...
  public static globalObject getGlobalObject() {
    if( _global == null ) _global = new GlobalObject();
    return _global;
  }
} // end class GlobalObject

4. Then in your servlet base class, you have:

GlobalObject _servletGlobalObject = GlobalObject.getGlobalObject();

You never call the constructor yourself, you let the GlobalObject class
handle the instantiation and give you the static object.

Hope this helps...

-S

Stuart Allen wrote:
> 
> ----------------------------------------------------
> Please read the FAQ at <http://java.apache.org/faq/>
> It does have a search feature!
> 
> We cannot guess what you are trying to do:
> #1. Include version numbers for all software.
> #2. Include relevant configuration settings.
> #3. Include full descriptions of the problem.
> 
> Got Linux? Seeing lots of java processes?
> <http://java.apache.org/faq/?file=274>
> ----------------------------------------------------
> 
> Hello
> 
> I am having a problem finding a successful way of sharing data between two
> servlets. I have tried two methods so far, both of which end up with a
> separate set of data for each servlet that access it. The first involved
> making a superclass with global static variables. Any servlet requiring
> access to this single-source data would extend this class. The second
> involved making a class containing a pointer to an instance of itself in
> the form of a private static variable. The value of this variable is then
> read by two other servlets using a public function call.
> 
> Any information as to why two separate instances of the data are being
> created in both cases would be greatly appreciated.
> 
> Regards,
> Stuart
> 
> --
> --------------------------------------------------------------
> Please read the FAQ! <http://java.apache.org/faq/>
> To subscribe:        [EMAIL PROTECTED]
> To unsubscribe:      [EMAIL PROTECTED]
> Archives and Other:  <http://java.apache.org/main/mail.html>
> Problems?:           [EMAIL PROTECTED]

-- 
"If you watch TV news, you know less about the world than if you just
drank
gin straight from the bottle."  - Garrison Keillor


--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to