You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Luis Rivera <lu...@gmail.com> on 2007/01/15 20:32:41 UTC

Keeping the server side object alive !!!

   Hi,

I would like to know how could I jump start my web service in tomcat before
any call from the client is made. My first version only needed to be
stateless and that worked fine, since I noticed that each call from the
client creates a new object in the server. However, now I would like to
create some threads because I have a custom administration module
(session/security/database).

I can create them when the first call is made (using statics), but I would
like to get rid of the overhead in the first call by somehow jump starting
the application to do the loading and initialization that the application
threads need to do, so that the when the first call is made, there is no
overhead to pay.

I am not sure. Is this possible? I am probably not understanding fully the
servlet model or how tomcat/axis is supposed to be stateful at the server
side.

I guess, if there is a smarter way to do this without using threads/statics
I would like to know where I could find an example.

   Thanks in advance,
   --Luis R.

Re: Keeping the server side object alive !!!

Posted by Andre Prasetya <an...@gmail.com>.
I attach an example for you.

MigrationUtil is a helper class that needs initialisation when the webapp
started and needs cleaning when the webapp stopped

On 1/16/07, Luis Rivera <lu...@gmail.com> wrote:
>
>    Dear Leon,
>
> Thanks for the info, I am reading about Contexts, but I am not sure if
> they
> are created as soon as tomcat starts. This listener seems to be event
> based,
> as long as an event is auto generated after Tomcat has started, it would
> work, or if there is another mechanism that can be used to generate the
> event that is automatic and that does not require a request from the
> client,
> I think it might work.
>
>     Thanks in advance,
>     --Luis R.
>
> On 1/15/07, Leon Rosenberg <ro...@googlemail.com> wrote:
> >
> > I think what you need is a ContextListener. With it, you will be
> > notified when the context (webapp) starts and can perform
> > initialization, and when the context is destroyed you can perform
> > de-initialization (stop your threads, cleanup ressources and such).
> >
> > regards
> > Leon
> >
> > On 1/15/07, Luis Rivera <lu...@gmail.com> wrote:
> > >    Hi,
> > >
> > > I would like to know how could I jump start my web service in tomcat
> > before
> > > any call from the client is made. My first version only needed to be
> > > stateless and that worked fine, since I noticed that each call from
> the
> > > client creates a new object in the server. However, now I would like
> to
> > > create some threads because I have a custom administration module
> > > (session/security/database).
> > >
> > > I can create them when the first call is made (using statics), but I
> > would
> > > like to get rid of the overhead in the first call by somehow jump
> > starting
> > > the application to do the loading and initialization that the
> > application
> > > threads need to do, so that the when the first call is made, there is
> no
> > > overhead to pay.
> > >
> > > I am not sure. Is this possible? I am probably not understanding fully
> > the
> > > servlet model or how tomcat/axis is supposed to be stateful at the
> > server
> > > side.
> > >
> > > I guess, if there is a smarter way to do this without using
> > threads/statics
> > > I would like to know where I could find an example.
> > >
> > >    Thanks in advance,
> > >    --Luis R.
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > 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
> >
> >
>
>


-- 
-Andre-

People see things the way they are and say "why ?" I see things that never
were and say "Why not ?"

Re: Keeping the server side object alive !!!

Posted by Leon Rosenberg <ro...@googlemail.com>.
On 1/15/07, Luis Rivera <lu...@gmail.com> wrote:
>    Dear Leon,
>
> Thanks for the info, I am reading about Contexts, but I am not sure if they
> are created as soon as tomcat starts.

As soon as tomcat deploys your webapp which is effectively the same
(depends on your settings like autodeploy etc, but in most cases the
same).

>This listener seems to be event based,
> as long as an event is auto generated after Tomcat has started, it would
> work, or if there is another mechanism that can be used to generate the
> event that is automatic and that does not require a request from the client,
> I think it might work.

i think it's considered 'best practice' to perform initialization in
the context listener.
at least its smooth :-)

regards
Leon

>
>     Thanks in advance,
>     --Luis R.
>
> On 1/15/07, Leon Rosenberg <ro...@googlemail.com> wrote:
> >
> > I think what you need is a ContextListener. With it, you will be
> > notified when the context (webapp) starts and can perform
> > initialization, and when the context is destroyed you can perform
> > de-initialization (stop your threads, cleanup ressources and such).
> >
> > regards
> > Leon
> >
> > On 1/15/07, Luis Rivera <lu...@gmail.com> wrote:
> > >    Hi,
> > >
> > > I would like to know how could I jump start my web service in tomcat
> > before
> > > any call from the client is made. My first version only needed to be
> > > stateless and that worked fine, since I noticed that each call from the
> > > client creates a new object in the server. However, now I would like to
> > > create some threads because I have a custom administration module
> > > (session/security/database).
> > >
> > > I can create them when the first call is made (using statics), but I
> > would
> > > like to get rid of the overhead in the first call by somehow jump
> > starting
> > > the application to do the loading and initialization that the
> > application
> > > threads need to do, so that the when the first call is made, there is no
> > > overhead to pay.
> > >
> > > I am not sure. Is this possible? I am probably not understanding fully
> > the
> > > servlet model or how tomcat/axis is supposed to be stateful at the
> > server
> > > side.
> > >
> > > I guess, if there is a smarter way to do this without using
> > threads/statics
> > > I would like to know where I could find an example.
> > >
> > >    Thanks in advance,
> > >    --Luis R.
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > 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: Keeping the server side object alive !!!

Posted by Andre Prasetya <an...@gmail.com>.
I attach an example for you.

MigrationUtil is a helper class that needs initialisation when the webapp
started and needs cleaning when the webapp stopped

On 1/16/07, Luis Rivera <lu...@gmail.com> wrote:
>
>    Dear Leon,
>
> Thanks for the info, I am reading about Contexts, but I am not sure if
> they
> are created as soon as tomcat starts. This listener seems to be event
> based,
> as long as an event is auto generated after Tomcat has started, it would
> work, or if there is another mechanism that can be used to generate the
> event that is automatic and that does not require a request from the
> client,
> I think it might work.
>
>     Thanks in advance,
>     --Luis R.
>
> On 1/15/07, Leon Rosenberg <ro...@googlemail.com> wrote:
> >
> > I think what you need is a ContextListener. With it, you will be
> > notified when the context (webapp) starts and can perform
> > initialization, and when the context is destroyed you can perform
> > de-initialization (stop your threads, cleanup ressources and such).
> >
> > regards
> > Leon
> >
> > On 1/15/07, Luis Rivera <lu...@gmail.com> wrote:
> > >    Hi,
> > >
> > > I would like to know how could I jump start my web service in tomcat
> > before
> > > any call from the client is made. My first version only needed to be
> > > stateless and that worked fine, since I noticed that each call from
> the
> > > client creates a new object in the server. However, now I would like
> to
> > > create some threads because I have a custom administration module
> > > (session/security/database).
> > >
> > > I can create them when the first call is made (using statics), but I
> > would
> > > like to get rid of the overhead in the first call by somehow jump
> > starting
> > > the application to do the loading and initialization that the
> > application
> > > threads need to do, so that the when the first call is made, there is
> no
> > > overhead to pay.
> > >
> > > I am not sure. Is this possible? I am probably not understanding fully
> > the
> > > servlet model or how tomcat/axis is supposed to be stateful at the
> > server
> > > side.
> > >
> > > I guess, if there is a smarter way to do this without using
> > threads/statics
> > > I would like to know where I could find an example.
> > >
> > >    Thanks in advance,
> > >    --Luis R.
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > 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
> >
> >
>
>


-- 
-Andre-

People see things the way they are and say "why ?" I see things that never
were and say "Why not ?"

Re: Keeping the server side object alive !!!

Posted by Luis Rivera <lu...@gmail.com>.
   Dear Leon,

Thanks for the info, I am reading about Contexts, but I am not sure if they
are created as soon as tomcat starts. This listener seems to be event based,
as long as an event is auto generated after Tomcat has started, it would
work, or if there is another mechanism that can be used to generate the
event that is automatic and that does not require a request from the client,
I think it might work.

    Thanks in advance,
    --Luis R.

On 1/15/07, Leon Rosenberg <ro...@googlemail.com> wrote:
>
> I think what you need is a ContextListener. With it, you will be
> notified when the context (webapp) starts and can perform
> initialization, and when the context is destroyed you can perform
> de-initialization (stop your threads, cleanup ressources and such).
>
> regards
> Leon
>
> On 1/15/07, Luis Rivera <lu...@gmail.com> wrote:
> >    Hi,
> >
> > I would like to know how could I jump start my web service in tomcat
> before
> > any call from the client is made. My first version only needed to be
> > stateless and that worked fine, since I noticed that each call from the
> > client creates a new object in the server. However, now I would like to
> > create some threads because I have a custom administration module
> > (session/security/database).
> >
> > I can create them when the first call is made (using statics), but I
> would
> > like to get rid of the overhead in the first call by somehow jump
> starting
> > the application to do the loading and initialization that the
> application
> > threads need to do, so that the when the first call is made, there is no
> > overhead to pay.
> >
> > I am not sure. Is this possible? I am probably not understanding fully
> the
> > servlet model or how tomcat/axis is supposed to be stateful at the
> server
> > side.
> >
> > I guess, if there is a smarter way to do this without using
> threads/statics
> > I would like to know where I could find an example.
> >
> >    Thanks in advance,
> >    --Luis R.
> >
> >
>
> ---------------------------------------------------------------------
> 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: Keeping the server side object alive !!!

Posted by Leon Rosenberg <ro...@googlemail.com>.
I think what you need is a ContextListener. With it, you will be
notified when the context (webapp) starts and can perform
initialization, and when the context is destroyed you can perform
de-initialization (stop your threads, cleanup ressources and such).

regards
Leon

On 1/15/07, Luis Rivera <lu...@gmail.com> wrote:
>    Hi,
>
> I would like to know how could I jump start my web service in tomcat before
> any call from the client is made. My first version only needed to be
> stateless and that worked fine, since I noticed that each call from the
> client creates a new object in the server. However, now I would like to
> create some threads because I have a custom administration module
> (session/security/database).
>
> I can create them when the first call is made (using statics), but I would
> like to get rid of the overhead in the first call by somehow jump starting
> the application to do the loading and initialization that the application
> threads need to do, so that the when the first call is made, there is no
> overhead to pay.
>
> I am not sure. Is this possible? I am probably not understanding fully the
> servlet model or how tomcat/axis is supposed to be stateful at the server
> side.
>
> I guess, if there is a smarter way to do this without using threads/statics
> I would like to know where I could find an example.
>
>    Thanks in advance,
>    --Luis R.
>
>

---------------------------------------------------------------------
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