Terence So wrote:

> Hi all,
>
> I have a servlet that will create new object(s) in my machine for each
> request of the client to that servlet.
> Those objects created will stay in the memory until the program finish and
> serve for other kind of request.
> In most case, the program work fine. But if object(s) are
> continuous creating.... will it consume all the memory in my machine and
> crash the machine?
> If this is the case, what can I do with it??
> Can anyone suggest any design approach to situation lik that?
> Any help will be greatly appreciated.
>
> Terence


You can try to reuse the objects by creating singleton or using static classes.
Singletons
are classes that are written so that there is only one object of that class


public class Singleton {
static Singleton singleton;
--- member variables -----

  public static Singleton getInstance() {
    if (singleton == null)
        singleton = new Singleton();
        return singleton;
  }
  private Singleton() {
    ---- constructor code --
  }

  ---- various set methods for member variables ----
}


Now in your main class you do

   Singleton myCopy = Singleton.getInstance();
   myCopysetXXX
   --------------

   Now use myCopy

==--==--==--==--==--==--==--==--==--==--==--==--==--==
S.Ramaswamy
Matrix Infotech Syndicate
D-7, Poorti, Vikaspuri, New Delhi, 110018, India
PHONE:    +91-11-5610050,   FAX: +91-11-5535103
WEB         http://MatrixInfotech.HyperMart.Net
==--==--==--==--==--==--==--==--==--==--==--==--==--==

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to