DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    hrishi Guest

    Application level object


    Hi All

    I am have apache tomcat 4.0 server and very new to java. Can any one give
    me pointers how to create a object which can be accessed thru out the application.
    Sort of an singleton object. I need to instanciate this object once the server
    starts and destroy it on the shutting down the app.

    Thanks in advance.
    hrishi.

  2. #2
    Guest

    Re: Application level object


    "hrishi" <hrishidhruv@hotmail.com> wrote:
    >
    >Hi All
    >
    >I am have apache tomcat 4.0 server and very new to java. Can any one give
    >me pointers how to create a object which can be accessed thru out the application.
    >Sort of an singleton object. I need to instanciate this object once the

    server
    >starts and destroy it on the shutting down the app.
    >
    >Thanks in advance.
    >hrishi.



    You have several options. You could create static methods on some class
    and never have to instantiate an object at all. You could create a singleton
    object, as you've suggested. The idiom to do this is to make the constructor
    private and provide a getInstance() method that returns a reference to a
    private member variable initiliazed to the one and only instance of the class
    during class initialization. Try googling for "java singleton" and you'll
    find examples and discussions. Finally, you could create a normal instance
    of the object and store it in the ServletContext (application intrinsic variable
    in JSP). How you choose to bootstrap that instance is up to you and your
    environment, but you could simply check for its existence before use and
    create it if it doesn't exist yet.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links