You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kamil Burzynski <no...@data.pl> on 2007/09/18 22:07:35 UTC

Sticky servlet

Hello,

 I would like to create one of my servlets to be 'sticky': to be sure
that Tomcat will never try to remove this servlet from memory.
Is <load-on-startup> enough? I know that it will start my servlet as
soon as tomcat starts, but will tomcat ever try to remove such servlet?
E.g. if there will be 1 month of inactivity, or so much requests arrive
that out-of-memory will happen?
Maybe I should create some background thread or socket or whatever?

Any solutions appreciated, thanks in advance.

-- 
Best regards from
Kamil Burzynski


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Sticky servlet

Posted by David Smith <dn...@cornell.edu>.
However.... if you read servlet spec 2.4, SRV.2.3.4 you'll find the 
following direct quote:

"The servlet container is not required to keep a servlet loaded for any 
particular
period of time. A servlet instance may be kept active in a servlet 
container for a
period of milliseconds, for the lifetime of the servlet container (which 
could be a
number of days, months, or years), or any amount of time in between."

I think you should give up on the whole idea of trying to keep a servlet 
operating for the life of tomcat.  Look at the reasons why you want this 
and look at other solutions to those problems.

--David

David Delbecq wrote:
> In j2ee specs, there is no provision for unloading an unused servlet. 
> Once a servlet has been tarted (load-on-startup or triggered by user 
> query), i never get unloaded, unless webapp gets unloaded, which 
> occurs at shutdown or during a redeploy (administrative task)
> Kamil Burzynski a écrit :
>> Hello,
>>
>>  I would like to create one of my servlets to be 'sticky': to be sure
>> that Tomcat will never try to remove this servlet from memory.
>> Is <load-on-startup> enough? I know that it will start my servlet as
>> soon as tomcat starts, but will tomcat ever try to remove such servlet?
>> E.g. if there will be 1 month of inactivity, or so much requests arrive
>> that out-of-memory will happen?
>> Maybe I should create some background thread or socket or whatever?
>>
>> Any solutions appreciated, thanks in advance.
>>
>>   
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re[2]: Sticky servlet

Posted by Kamil Burzynski <no...@data.pl>.
Hello,

> In j2ee specs, there is no provision for unloading an unused servlet. 
> Once a servlet has been tarted (load-on-startup or triggered by user 
> query), i never get unloaded, unless webapp gets unloaded, which occurs
> at shutdown or during a redeploy (administrative task)

Thanks for quick reply. So, it seems, that I have guarantee, that my
servlet once started, will live as long as my webapp/tomcat will live..
this is exactly what I was looking for.

-- 
Best regards from
Kamil Burzynski


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Sticky servlet

Posted by David Delbecq <de...@oma.be>.
In j2ee specs, there is no provision for unloading an unused servlet. 
Once a servlet has been tarted (load-on-startup or triggered by user 
query), i never get unloaded, unless webapp gets unloaded, which occurs 
at shutdown or during a redeploy (administrative task)
Kamil Burzynski a écrit :
> Hello,
>
>  I would like to create one of my servlets to be 'sticky': to be sure
> that Tomcat will never try to remove this servlet from memory.
> Is <load-on-startup> enough? I know that it will start my servlet as
> soon as tomcat starts, but will tomcat ever try to remove such servlet?
> E.g. if there will be 1 month of inactivity, or so much requests arrive
> that out-of-memory will happen?
> Maybe I should create some background thread or socket or whatever?
>
> Any solutions appreciated, thanks in advance.
>
>   

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Sticky servlet

Posted by Mikolaj Rydzewski <mi...@ceti.pl>.
Kamil Burzynski wrote:
>  I would like to create one of my servlets to be 'sticky': to be sure
> that Tomcat will never try to remove this servlet from memory.
> Is <load-on-startup> enough? I know that it will start my servlet as
> soon as tomcat starts, but will tomcat ever try to remove such servlet?
>   
Why do you want such a solution? Even if Tomcat will unload your servlet 
for some reason, it will load it again with first user request directed 
to this servlet.

Have you considered using ServletContextListener? Maybe it will suit you 
better?
> E.g. if there will be 1 month of inactivity, or so much requests arrive
> that out-of-memory will happen
OOM will kill entire Tomcat anyway.

-- 
Mikolaj Rydzewski <mi...@ceti.pl>


Re[2]: Sticky servlet

Posted by Kamil Burzynski <no...@data.pl>.
Hello,

> I see no reason you would need your servlet to stay in memory. As long
> as it is alive when needed (that is when requests arrive) it's enough.
> Maybe you problem is that it does much than serving request, like 
> running background thread, send message to people and so on. Then you 

Exactly. I am using some external API which is receiving endless data
stream (namely stock price changes), and have to be running 24h, every
day. Running a background thread or something like this would do for me.
Answering mere HTTP requests is not enough.

> might simply need to separate the servlet (part that answer a client) 
> from the service object (part that handle various thread). The service

Yes, I was considering running some 'background' daemon for that.

> object could be started/stopped by a simple servletContextListener and
> attached to JNDI. The servlet would then request that object from JNDI.

I have no knowledge (yet) in servletContextListener and JNDI yet (and
this may be the sole reason why I am asking such questions instead of
just using it), but from your mail I reckon, that it will just be the
solution for me. I have to google for this now.

> If you don't like to use JNDI you can still attach it to application scope.

I dont know yet if I like JNDI ;)

> This will be more easy to maintain and more performant than delegating
> work to another server and add an other row of TCP/IP packets.

Yeah, I was concerned about performance and complexity of my alternative
solution (separate executable + tcp socket + custom protocol or at least
some rpc which would use a lot of xml).

> Kamil Burzynski a écrit :
>> Hello,
>>
>>   
>>> Please read the other responses to this thread, since they are correct that
>>> there is no guarantee.  However, the current implementation of TC (3.3-6.0)
>>> will not unload a Servlet unless the entire context is reloaded (with a
>>> slight exception for JSP pages).  But then you are programming against
>>> Tomcat itself, in an area where there is no guarantee that it won't change
>>> in the future, and it may not work if you try to move to another Servlet
>>> container.
>>>     
>>
>> Yeah, I was afraid of getting such answer, actually ;) In my project it
>> would be enough to code against current version of Tomcat, though I
>> would like a clean solution. So, it seems, that I'll do standalone
>> server and then webapp will connect to it via some protocol (I am not
>> familiar with java world enough to know if any good rpc is there - most
>> probably it is).
>>
>> Thanks for all answers.
>>
>>   

> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org



-- 
Best regards from
Kamil Burzynski


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Sticky servlet

Posted by David Delbecq <de...@oma.be>.
I see no reason you would need your servlet to stay in memory. As long 
as it is alive when needed (that is when requests arrive) it's enough. 
Maybe you problem is that it does much than serving request, like 
running background thread, send message to people and so on. Then you 
might simply need to separate the servlet (part that answer a client) 
from the service object (part that handle various thread). The service 
object could be started/stopped by a simple servletContextListener and 
attached to JNDI. The servlet would then request that object from JNDI. 
If you don't like to use JNDI you can still attach it to application scope.
This will be more easy to maintain and more performant than delegating 
work to another server and add an other row of TCP/IP packets.


Kamil Burzynski a écrit :
> Hello,
>
>   
>> Please read the other responses to this thread, since they are correct that
>> there is no guarantee.  However, the current implementation of TC (3.3-6.0)
>> will not unload a Servlet unless the entire context is reloaded (with a
>> slight exception for JSP pages).  But then you are programming against
>> Tomcat itself, in an area where there is no guarantee that it won't change
>> in the future, and it may not work if you try to move to another Servlet
>> container.
>>     
>
> Yeah, I was afraid of getting such answer, actually ;) In my project it
> would be enough to code against current version of Tomcat, though I
> would like a clean solution. So, it seems, that I'll do standalone
> server and then webapp will connect to it via some protocol (I am not
> familiar with java world enough to know if any good rpc is there - most
> probably it is).
>
> Thanks for all answers.
>
>   

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re[2]: Sticky servlet

Posted by Kamil Burzynski <no...@data.pl>.
Hello,

> Please read the other responses to this thread, since they are correct that
> there is no guarantee.  However, the current implementation of TC (3.3-6.0)
> will not unload a Servlet unless the entire context is reloaded (with a
> slight exception for JSP pages).  But then you are programming against
> Tomcat itself, in an area where there is no guarantee that it won't change
> in the future, and it may not work if you try to move to another Servlet
> container.

Yeah, I was afraid of getting such answer, actually ;) In my project it
would be enough to code against current version of Tomcat, though I
would like a clean solution. So, it seems, that I'll do standalone
server and then webapp will connect to it via some protocol (I am not
familiar with java world enough to know if any good rpc is there - most
probably it is).

Thanks for all answers.

-- 
Best regards from
Kamil Burzynski


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Sticky servlet

Posted by Bill Barker <wb...@wilshire.com>.
"Kamil Burzynski" <no...@data.pl> wrote in message 
news:325227822.20070918220735@data.pl...
> Hello,
>
> I would like to create one of my servlets to be 'sticky': to be sure
> that Tomcat will never try to remove this servlet from memory.
> Is <load-on-startup> enough? I know that it will start my servlet as
> soon as tomcat starts, but will tomcat ever try to remove such servlet?
> E.g. if there will be 1 month of inactivity, or so much requests arrive
> that out-of-memory will happen?
> Maybe I should create some background thread or socket or whatever?
>

Please read the other responses to this thread, since they are correct that 
there is no guarantee.  However, the current implementation of TC (3.3-6.0) 
will not unload a Servlet unless the entire context is reloaded (with a 
slight exception for JSP pages).  But then you are programming against 
Tomcat itself, in an area where there is no guarantee that it won't change 
in the future, and it may not work if you try to move to another Servlet 
container.

> Any solutions appreciated, thanks in advance.
>
> -- 
> Best regards from
> Kamil Burzynski
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
> 




---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org