• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

load on start up

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

can we have multiple servlets running in infinite loop with load-on-startup?

Thanks,
Visu Nekk
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you explain more please? I don't understand.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by visu Nekk:
can we have multiple servlets running in infinite loop with load-on-startup?



I could not get the meaning of servlets running in infinite loop?
 
visu Nekk
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have 5 servlets each doing a specific task and this has to happen round the clock. Hence I placed the business logic in an infinite loop and in the web.xml, I put them load-on-startup to a positive integer and hot deployed the code. But what's happening is, only one servlet is being processed.

Thanks,
Visu Nekk
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the following is happening in your case.

You first servlet loads up as you have set load-on-startup to be positive.The container runs the code in init method of that servlet and never returns from that method(as that is an infinite loop).That is the issue.

You can start off a individual thread for each process and you do not need five servlets to kick off five threads.It can be done using only one servlet ,or ContextListner is even better suited for this task.

Hope this helps,
 
visu Nekk
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rahul,

But can we place an infinite loop in a ContextListener. It its possible, will I be able to access the index page of the web application.

Visu Nekk
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by visu Nekk:
But can we place an infinite loop in a ContextListener. It its possible, will I be able to access the index page of the web application.



Hi Visu,

I guess I am missing something or you are.

I have asked you to execute the infinite loop in a separate thread and use context listener to kick off the thread.
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by visu Nekk:
Hi,

I have 5 servlets each doing a specific task and this has to happen round the clock.



It seems what you need is a scheduler. Did you evaluate Quartz (http://www.opensymphony.com/quartz/). This will do your job neatly without you having to get into the intricacies of multithreading.
 
visu Nekk
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rahul and Sunil,

How about using a TimerTask in tandem with a servlet or ContextListener?

Visu
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Directly we can't use TimerTask, because it's an abstract class, so first of first you need to extend it in term to use it.

Once you extend it in any class then after you can use that class with Timer class. So to start that task you can use this Timer class with Servlet or ContextListener.


TimerTask is best to use when ever you want to detach you task from your normal routine.


Ashok Mor
Ness Tech.
[ July 18, 2007: Message edited by: Ashok Mor ]
 
visu Nekk
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ashok,

From a servlet, if I invoke a class that extends TimerTask, does the servlet maintain any reference to that class once the class is invoked. Because I have a doubt that since servlet is multithreaded, and we are spawning a new thread from the servlet, the servlet will be holding a reference to that thread, whcih might affect the performance. Could you please clarify this?

Visu
 
Ashok Mor
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure Visu.



You must be knowing Servlet right ???


So for Servlet we can have an init(..) method � and this init() method will be called once ever in it�s entirety, So what you can do is, just create an instance of Timer class in this servlet and initiate it in init(..) method. So there there will be a single instance of Timer, and it want create an issue like performance.


Is this clear to you ???


Ashok Mor,
Ness Technology.
 
visu Nekk
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ashok,

It worked out and is working fine.
 
Ashok Mor
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are always welcome Vishu......
 
reply
    Bookmark Topic Watch Topic
  • New Topic