• 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

Are listener and filter objects reused after a context reload?

 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ranchers,

I have a simple question for which someone here surely has an answer :-)

I'd like to know if web application components like the well-known filters and listeners are recycled if the application context is reloaded (for example with the manager application). I tested this with Tomcat 6.0.20 which is using servlet API 2.5 and in this case a new test filter is created every time I reload the context (which is the way I'd prefer it).

I'm just not sure if it's guaranteed by the spec that filters and listeners are NOT reused during context reloads. Or could it be possible that only the corresponding lifecycle methods are called but the objects themselves are reused? I guess it would be more safe for cleaning up everything correctly to throw away the objects and create new ones from scratch. Perhaps someone can point me to some information about this topic?!?

Thanks in advance!

Marco
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The J2EE spec, to my knowledge, does not dictate how applications are reloaded in memory. Application containers have layers of classloaders that will automatically reload the application in memory when you redeploy. How this process happens in dependent on the application server and its underlying class loader.
 
Marco Ehrentreich
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Deepak,

thanks a lot for your answer!

Unfortunately it seems my question should've been more precise I'm not really concerned about classloading issues. Some concrete things I'd like to know are for example if filters and listeners are guaranteed to be reinitialized each time the context is reloaded/the application is started? What exactly happens to attributes in the different scopes (context, session, ...)? Is the web.xml descriptor re-read after a context reload?

Even though classloading and creation of objects is up to the container I can hardly imagine that the said things above are not defined anywhere in the spec. I think I even read about this some time ago but I couldn't find the relevant documentation now. Perhaps you know an answer to some of my questions or you can point me to more information about these topics.

Marco
 
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Marco,

I believe, by context reload you mean the restarting the JVM. If we restart the JVM all the related objects would become available for garbage collection.

 
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marco.
Reloading means, stop the current application and start it again. When the application stops, all the objects and its attributes will be lost. During startup, the container must read web.xml and everything will be done as planned.
 
Marco Ehrentreich
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I believe, by context reload you mean the restarting the JVM.


No, by context reload I meant exactly context reload, i.e. reloading a specific web application context

But Chinmaya already gave exactly the answers I was looking for This cleared my doubts about what "context reload" exactly means for the components of a Java web applications! I was just not sure if a reload does more or less or the same than what a "normal" application start would do.

Anyway, thank you all for taking the time to answer my question!

Marco
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic