You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Wes Devauld <we...@devauld.ca> on 2003/01/24 16:25:41 UTC

Re: AXIS App. Design/Architecture

The approach you can take is to create your 'Manager' classes as singletons.
 The idea is to make the constructors for the class private and then use
Manager.getInstance() like calls to get a hold of the object.  An example




class Manager {


  private Manager theOne;


  private Manager() {


    //Create your object


  }


  public Manager getInstance() {


     if(theOne == null) {


         theOne = new Manager();


     }


     return theOne;


  }


}




If you need to make sure the Manager object exits cleanly you will need to
implement a ContextListener (implement javax.servlet.ServletContextListener)
in Tomcat, and configure your web.xml to use the Listener.  The listener
recieves notification for events like the server shutting down.  You can
then have the ContextListener call a Manager.shutdown() like call.




Hope this helps,


-W




>


> Hi,


> This is my first time designing and implementing a system on AXIS. I'm


> trying to design an application that will require the use of such


> resources as sockets, database connections, file I/O.&nbsp;If i'm not


> mistaken, whenever I invoke a method on an object that is running on


> top of the AXIS servlet, that object is instantiated and threaded. For


> example, I have, say a 'Server' object, that implements a logOn(),


> logOff(), createUser(), listUsers() methods. These methods all connect


> to a database and do some type of file logging. Since the 'Server'


> object will be threaded for each session, I&nbsp;foresee issues&nbsp;in


> resource conflicts/management and race conditions&nbsp;('classical'


> issues&nbsp;regarding multi-threaded design)&nbsp;when multiple


> 'Server' threads have been spawned.&nbsp; I had the idea of


> using&nbsp;'static' 'Manager' classes (DBManager, SocketManager) to


> manage these pools of resources. Is there an approach to instantiate a


> single, static 'Manager' class (that will not destroyed until the AXIS


> servlet is shutdown) that these threaded objects can all commonly use


> to do this type of resource management? Regards,


> Nicolas Dinh


> &nbsp;The new  MSN 8:  smart spam protection and 2 months FREE*






Re: AXIS App. Design/Architecture

Posted by Steve Parker <st...@naweb.com>.
Yes, and remember to make the getInstance() method static so you can call it 
before the class has been instantiated.  

On Fri, 24 Jan 2003 08:25:41 -0700 (MST), Wes Devauld wrote
> The approach you can take is to create your 'Manager' classes as singletons.
>  The idea is to make the constructors for the class private and then 
> use Manager.getInstance() like calls to get a hold of the object.  
> An example
> 
> class Manager {
> 
>   private Manager theOne;
> 
>   private Manager() {
> 
>     //Create your object
> 
>   }
> 
>   public Manager getInstance() {
> 
>      if(theOne == null) {
> 
>          theOne = new Manager();
> 
>      }
> 
>      return theOne;
> 
>   }
> 
> }
> 
> If you need to make sure the Manager object exits cleanly you will 
> need to implement a ContextListener (implement 
> javax.servlet.ServletContextListener) in Tomcat, and configure your 
> web.xml to use the Listener.  The listener recieves notification for 
> events like the server shutting down.  You can then have the 
> ContextListener call a Manager.shutdown() like call.
> 
> Hope this helps,
> 
> -W
> 
> >
> 
> > Hi,
> 
> > This is my first time designing and implementing a system on AXIS. I'm
> 
> > trying to design an application that will require the use of such
> 
> > resources as sockets, database connections, file I/O.&nbsp;If i'm not
> 
> > mistaken, whenever I invoke a method on an object that is running on
> 
> > top of the AXIS servlet, that object is instantiated and threaded. For
> 
> > example, I have, say a 'Server' object, that implements a logOn(),
> 
> > logOff(), createUser(), listUsers() methods. These methods all connect
> 
> > to a database and do some type of file logging. Since the 'Server'
> 
> > object will be threaded for each session, I&nbsp;foresee issues&nbsp;in
> 
> > resource conflicts/management and race conditions&nbsp;('classical'
> 
> > issues&nbsp;regarding multi-threaded design)&nbsp;when multiple
> 
> > 'Server' threads have been spawned.&nbsp; I had the idea of
> 
> > using&nbsp;'static' 'Manager' classes (DBManager, SocketManager) to
> 
> > manage these pools of resources. Is there an approach to instantiate a
> 
> > single, static 'Manager' class (that will not destroyed until the AXIS
> 
> > servlet is shutdown) that these threaded objects can all commonly use
> 
> > to do this type of resource management? Regards,
> 
> > Nicolas Dinh
> 
> > &nbsp;The new  MSN 8:  smart spam protection and 2 months FREE*





Re: AXIS App. Design/Architecture

Posted by Steve Parker <st...@naweb.com>.
Yes, and remember to make the getInstance() method static so you can call it 
before the class has been instantiated.  

On Fri, 24 Jan 2003 08:25:41 -0700 (MST), Wes Devauld wrote
> The approach you can take is to create your 'Manager' classes as singletons.
>  The idea is to make the constructors for the class private and then 
> use Manager.getInstance() like calls to get a hold of the object.  
> An example
> 
> class Manager {
> 
>   private Manager theOne;
> 
>   private Manager() {
> 
>     //Create your object
> 
>   }
> 
>   public Manager getInstance() {
> 
>      if(theOne == null) {
> 
>          theOne = new Manager();
> 
>      }
> 
>      return theOne;
> 
>   }
> 
> }
> 
> If you need to make sure the Manager object exits cleanly you will 
> need to implement a ContextListener (implement 
> javax.servlet.ServletContextListener) in Tomcat, and configure your 
> web.xml to use the Listener.  The listener recieves notification for 
> events like the server shutting down.  You can then have the 
> ContextListener call a Manager.shutdown() like call.
> 
> Hope this helps,
> 
> -W
> 
> >
> 
> > Hi,
> 
> > This is my first time designing and implementing a system on AXIS. I'm
> 
> > trying to design an application that will require the use of such
> 
> > resources as sockets, database connections, file I/O.&nbsp;If i'm not
> 
> > mistaken, whenever I invoke a method on an object that is running on
> 
> > top of the AXIS servlet, that object is instantiated and threaded. For
> 
> > example, I have, say a 'Server' object, that implements a logOn(),
> 
> > logOff(), createUser(), listUsers() methods. These methods all connect
> 
> > to a database and do some type of file logging. Since the 'Server'
> 
> > object will be threaded for each session, I&nbsp;foresee issues&nbsp;in
> 
> > resource conflicts/management and race conditions&nbsp;('classical'
> 
> > issues&nbsp;regarding multi-threaded design)&nbsp;when multiple
> 
> > 'Server' threads have been spawned.&nbsp; I had the idea of
> 
> > using&nbsp;'static' 'Manager' classes (DBManager, SocketManager) to
> 
> > manage these pools of resources. Is there an approach to instantiate a
> 
> > single, static 'Manager' class (that will not destroyed until the AXIS
> 
> > servlet is shutdown) that these threaded objects can all commonly use
> 
> > to do this type of resource management? Regards,
> 
> > Nicolas Dinh
> 
> > &nbsp;The new  MSN 8:  smart spam protection and 2 months FREE*





Re: AXIS App. Design/Architecture

Posted by Steve Parker <st...@naweb.com>.
Yes, and remember to make the getInstance() method static so you can call it 
before the class has been instantiated.  

On Fri, 24 Jan 2003 08:25:41 -0700 (MST), Wes Devauld wrote
> The approach you can take is to create your 'Manager' classes as singletons.
>  The idea is to make the constructors for the class private and then 
> use Manager.getInstance() like calls to get a hold of the object.  
> An example
> 
> class Manager {
> 
>   private Manager theOne;
> 
>   private Manager() {
> 
>     //Create your object
> 
>   }
> 
>   public Manager getInstance() {
> 
>      if(theOne == null) {
> 
>          theOne = new Manager();
> 
>      }
> 
>      return theOne;
> 
>   }
> 
> }
> 
> If you need to make sure the Manager object exits cleanly you will 
> need to implement a ContextListener (implement 
> javax.servlet.ServletContextListener) in Tomcat, and configure your 
> web.xml to use the Listener.  The listener recieves notification for 
> events like the server shutting down.  You can then have the 
> ContextListener call a Manager.shutdown() like call.
> 
> Hope this helps,
> 
> -W
> 
> >
> 
> > Hi,
> 
> > This is my first time designing and implementing a system on AXIS. I'm
> 
> > trying to design an application that will require the use of such
> 
> > resources as sockets, database connections, file I/O.&nbsp;If i'm not
> 
> > mistaken, whenever I invoke a method on an object that is running on
> 
> > top of the AXIS servlet, that object is instantiated and threaded. For
> 
> > example, I have, say a 'Server' object, that implements a logOn(),
> 
> > logOff(), createUser(), listUsers() methods. These methods all connect
> 
> > to a database and do some type of file logging. Since the 'Server'
> 
> > object will be threaded for each session, I&nbsp;foresee issues&nbsp;in
> 
> > resource conflicts/management and race conditions&nbsp;('classical'
> 
> > issues&nbsp;regarding multi-threaded design)&nbsp;when multiple
> 
> > 'Server' threads have been spawned.&nbsp; I had the idea of
> 
> > using&nbsp;'static' 'Manager' classes (DBManager, SocketManager) to
> 
> > manage these pools of resources. Is there an approach to instantiate a
> 
> > single, static 'Manager' class (that will not destroyed until the AXIS
> 
> > servlet is shutdown) that these threaded objects can all commonly use
> 
> > to do this type of resource management? Regards,
> 
> > Nicolas Dinh
> 
> > &nbsp;The new  MSN 8:  smart spam protection and 2 months FREE*





Re: AXIS App. Design/Architecture

Posted by Ricky Ho <ri...@cisco.com>.
Who is making the Manager.getInstance() call ?

Is it simpler by just declaring the object class in "application" scope ?

Rgds, Ricky

At 08:25 AM 1/24/2003 -0700, Wes Devauld wrote:
>The approach you can take is to create your 'Manager' classes as singletons.
>  The idea is to make the constructors for the class private and then use
>Manager.getInstance() like calls to get a hold of the object.  An example
>
>
>
>
>class Manager {
>
>
>   private Manager theOne;
>
>
>   private Manager() {
>
>
>     //Create your object
>
>
>   }
>
>
>   public Manager getInstance() {
>
>
>      if(theOne == null) {
>
>
>          theOne = new Manager();
>
>
>      }
>
>
>      return theOne;
>
>
>   }
>
>
>}
>
>
>
>
>If you need to make sure the Manager object exits cleanly you will need to
>implement a ContextListener (implement javax.servlet.ServletContextListener)
>in Tomcat, and configure your web.xml to use the Listener.  The listener
>recieves notification for events like the server shutting down.  You can
>then have the ContextListener call a Manager.shutdown() like call.
>
>
>
>
>Hope this helps,
>
>
>-W
>
>
>
>
> >
>
>
> > Hi,
>
>
> > This is my first time designing and implementing a system on AXIS. I'm
>
>
> > trying to design an application that will require the use of such
>
>
> > resources as sockets, database connections, file I/O.&nbsp;If i'm not
>
>
> > mistaken, whenever I invoke a method on an object that is running on
>
>
> > top of the AXIS servlet, that object is instantiated and threaded. For
>
>
> > example, I have, say a 'Server' object, that implements a logOn(),
>
>
> > logOff(), createUser(), listUsers() methods. These methods all connect
>
>
> > to a database and do some type of file logging. Since the 'Server'
>
>
> > object will be threaded for each session, I&nbsp;foresee issues&nbsp;in
>
>
> > resource conflicts/management and race conditions&nbsp;('classical'
>
>
> > issues&nbsp;regarding multi-threaded design)&nbsp;when multiple
>
>
> > 'Server' threads have been spawned.&nbsp; I had the idea of
>
>
> > using&nbsp;'static' 'Manager' classes (DBManager, SocketManager) to
>
>
> > manage these pools of resources. Is there an approach to instantiate a
>
>
> > single, static 'Manager' class (that will not destroyed until the AXIS
>
>
> > servlet is shutdown) that these threaded objects can all commonly use
>
>
> > to do this type of resource management? Regards,
>
>
> > Nicolas Dinh
>
>
> > &nbsp;The new  MSN 8:  smart spam protection and 2 months FREE*