Hello Donie and all others,

I think static classes are once per Java Virtual Machine. So 
your question could be extended to: Is it compatible with the 
specs to run all webapps within the same JVM? Is this behaviour 
supposed to be portable to other servlet containers and later 
versions of Tomcat?

I looked through the servlet spec and didn't find anything about 
it. As I'm very interested in this I would really appreciate if 
some of the list's specialists could answer this.

If this behaviour is portable: Couldn't this be used to easily 
communicate between webapps?

Donie, I think the easiest solution for you would be to have one 
static class with it's own class name per webapp, e.g. 
vMmscWebApp1, vMmscWebApp2.

A nicer solution would be a static class which holds references 
to instances (one per webapp) of the vMmsc-class.

Regards.

Andreas


On 15 Oct 2002 at 11:11, Donie Kelly wrote:

> Hi
> I have written a static class which is populated with data on startup of my
> servlets and is suppose to be use in the context of the request. However,
> the static class seems to return the same information for all webapps and
> holds the configuration of the last servlet run on startup. Here is the
> code... As you can see I want to use something that looks like the
> System.Properties but System.Properties is gloabal so it's no use to me. I
> want to be able to set the webapp name here so it's used during processing
> but at the moment it's only returning the last name configured for the last
> webapp.
> 
> Any ideas why this is happening. What have I done wrong to make this class
> appear global?
> Thanks
> Donie
> 
> 
> import org.apache.log4j.Category;
> import java.util.Hashtable;
> import java.util.Properties;
> import java.io.InputStream;
> 
> public class vMmsc
> {
> static Category log = Category.getInstance(vMmsc.class.getName());
> public final static String version = "$Revision:   1.3  $$Date:   10 Oct
> 2002 11:57:48  $";
> public static String getVersion() { return version; }
> private static Properties props=new Properties();
> 
>     // Defeats instantiation
>     private vMmsc(){}
>     
>     public static void load(InputStream is)
>     {
>         try
>         {
>             props.load(is);       
>         }
>         catch(Exception ex)
>         {
>             log.error("Problem loading property file: " + ex.getMessage());
> 
>         }
>     }
>     
>     public static void setProperty(String Name, String Value)
>     {
>         props.setProperty(Name, Value);
>     }
>     
>     public static String getProperty(String Name)
>     {
>         String Value = props.getProperty(Name);
>         if(Value==null || Value.equalsIgnoreCase(""))
>             log.debug("The property value " + Name + " is not defined");
>         return Value;
>     }
>     
>     public static String getProperty(String Name, String defaultValue)
>     {
>         String Value = props.getProperty(Name);
>         if(Value==null || Value.equalsIgnoreCase(""))
>         {
>             log.debug("The property value " + Name + " is returning it's
> default value");
>             return defaultValue;
>         }
>         return Value;
>     }
>     
>     public static Integer getInteger(String Name)
>     {
>         String Value = getProperty(Name);
>         if(Value==null || Value.equalsIgnoreCase(""))
>             log.debug("The property value " + Name + " is not defined");
>             
>         return new Integer(Value);
>     }
>     
>     public static Integer getInteger(String Name, int defaultValue)
>     {
>         String Value = getProperty(Name);
>         if(Value==null || Value.equalsIgnoreCase(""))
>         {
>             log.debug("The property value " + Name + " is returning it's
> default value");
>             return new Integer(defaultValue);
>         }    
>         return new Integer(Value);
>     }
> 
>     // Return true if property is enabled/yes/true
>     public static boolean isEnabled(String Name)
>     {
>         String Value = getProperty(Name);
>         
>         if(Value!=null)
>             if(Value.equalsIgnoreCase("yes") || 
>                 Value.equalsIgnoreCase("true") || 
>                 Value.equalsIgnoreCase("enabled") ||
>                 Value.equalsIgnoreCase("1"))
>                 return true;
>         return false;    
>     }
> }
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to