Thanks Sourabh and Michael, all replies help calm the storm in my head.
and in case of lazy initialization then i can reuse the object like that ...
List l = new ArrayList();
doGet(..) {
myObj obj = (myObj)l.get(index);
if (obj != null)
obj.doThat(...);
else {
obj = new myObj(...);
l.add(obj);
obj.doThat();
}
}
is that it ?
alain
On 30 Jan, Sourabh Kulkarni wrote:
> hi alain,
>
>> one of my concerns is: if i instanciate a class
>> in doGet, it is loaded in a thread each time the
>> servlet executes, so it should automatically
>> unload when the thread terminates, am i right?
>
> what do you want to say by "loaded"? If you are talking about loading of
> the class by the class-loader then it is loaded only once (until some change
> in class/jar file and reloading takes place) by the class-loader. If you
> wanted to talk about instance creation, then yes the object is created each
> time and is eligible for garbage collection after the thread dies (if you
> don't keep its reference somewhere in session or context).
>
>> but i saw some code like that inside doGet or doPost
>>
>> if there is an instance of my class
>> use it
>> else
>> create it
>>
>> is it necessary ?
>
> here possibly the object is stored somewhere in session or context or
> some other persistent reference, and then they check whether it was already
> present. Here again the multi-threaded access will take place depending on
> the place where the object was stored.
>
>> the instance of the class
>> if that class is instanciated inside doGet
>> should not exist anymore once doGet terminates
>>
> yes you are right..
>
>> i am confused because there are many ways
>> to do almost the same thing, well better have
>> too many ways than none...
> :-)
>
> hope this helps,
> -sourabh
>
> ___________________________________________________________________________
> 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
___________________________________________________________________________
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