• 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

Can JSP spawn persistent/independent serverside objects?

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I was wondering if anyone had utilized JSP to spawn objects that ran independently on the server, where independent means independent from the calling applications thread/session/lifetime. I am brand spanking new to JSP so do not be afraid to give lots of details if indeed this is possible or alternatives if not. Or alternatively, is it possible to have a global object on the server (similar to an application object in ASP) that comes into existence when the server is booted and persists till the server is shutdown? If both are possible, feel free to weigh in on the advantages or disadvantages of either or both.
Thanks in advance!
-MLA
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The short answer is no, you can only spawn objects for the lifetime of your application. This means basically that you can have an object in existance from the time your application is first run until it is destroyed. You can store these objects within the ServletContext (application scope for JSPs). Only applications which share the same ServletContext will have access to objects stored there.
It is possible on some servers to specify servlets to run at server startup I believe. A cheap hack is to make such a servlet which instantiates an object in its init() method and then places that object into the ServletContext. Now all other applications sharing that ServletContext have access to your object.
The preferred way is that each application has its own ServletContext, but I know that often people don't bother configuring things this way and throw all their servlets into one place. If this is your case, this might be a workaround for you.
Jason
 
Michael Arnett
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I utilize Enteprise Beans to accomplish this? Basically I am just trying to make one object responsible for inputting a batch of records into a database and another object to run on a schedule and periodically process some subset of database records...Thanks again for any help you can offer.
-MLA
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, you can't play thread games with EJB's! It's expressly forbidden by the EJB spec. You can do threads in servlets, subject to the limits of the servlet thread's lifespan, but EJBs can't do threads at all.
However, JMS is often a good solution if you want to trigger the task from a server event. Many J2EE server systems also have some sort of process that can be time-triggered.
Two examples. 1) In WebLogic, you can specify a WebLogic startup class (server-specific) task and use their timer services to do what you want. 2) In Unix/Linux using Tomcat, you can set up a "cron" task to run the process (Windows uses the "AT" command similarly).
 
I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic