jsr339-experts@jax-rs-spec.java.net

[jsr339-experts] Re: Fwd: [jax-rs-spec users] Lifecycle management in Application subclasses

From: Markus KARG <markus_at_headcrashing.eu>
Date: Fri, 14 Dec 2012 19:25:35 +0100

While I do not see an immediate need for this, I do not have any objections.
On the other hand the question is whether we need to provide a
JAX-RS-proprietary event for something which is possibly covered by existing
and more general APIs already?

> -----Original Message-----
> From: Bill Burke [mailto:bburke_at_redhat.com]
> Sent: Freitag, 14. Dezember 2012 01:52
> To: jsr339-experts_at_jax-rs-spec.java.net
> Subject: [jsr339-experts] Re: Fwd: [jax-rs-spec users] Lifecycle
> management in Application subclasses
>
> @PostCreate, @PreDestroy?
>
> On 12/13/2012 7:46 PM, Marek Potociar wrote:
> > Helo Experts,
> >
> > in case you have missed it, there was a request on our users mailing
> > list asking for adding Application.shutdown() hook into JAX-RS API. I
> > would like to ask you for a feedback on adding support for such
> > init/shutdown hook methods into JAX-RS Application class.
> >
> > Than you,
> > Marek
> >
> > Begin forwarded message:
> >
> >> *From: *James Shaw <js102_at_zepler.net <mailto:js102_at_zepler.net>>
> >> *Subject: **[jax-rs-spec users] Re: Lifecycle management in
> >> Application subclasses*
> >> *Date: *December 13, 2012 6:40:41 PM GMT+01:00
> >> *To: *users_at_jax-rs-spec.java.net <mailto:users_at_jax-rs-spec.java.net>
> >> *Reply-To: *users_at_jax-rs-spec.java.net
> >> <mailto:users_at_jax-rs-spec.java.net>
> >>
> >> On 13 December 2012 15:52, Marek Potociar <marek.potociar_at_oracle.com
> >> <mailto:marek.potociar_at_oracle.com>> wrote:
> >>>
> >>> On Dec 6, 2012, at 12:29 PM, James Shaw <js102_at_zepler.net
> >>> <mailto:js102_at_zepler.net>> wrote:
> >>>
> >>>> I hope this is the correct place to raise this.
> >>>>
> >>>> I was looking for an Application method I could override that
> would
> >>>> be executed when the servlet container shuts down (I have some
> >>>> ExecutorServices that need to be stopped)
> >>>>
> >>>> I couldn't find such a method, so I've worked around the problem
> by
> >>>> implementing my own ServletContextListener and exposing the
> >>>> ExecutorServices through a static accessor. Something like this:
> >>>>
> >>>> @ApplicationPath("/") public class MyApplication extends
> Application {
> >>>> public MyApplication() {
> >>>> LifecycleListener.getExecutorService();
> >>>> ...
> >>>> }
> >>>> }
> >>>>
> >>>> @WebListener public class LifecycleListener implements
> >>>> ServletContextListener { ... }
> >>>>
> >>>> Has adding an Application.shutdown() hook to JAX-RS been discussed
> >>>> before? Is there another way I ought to be doing this?
> >>>
> >>> It hasn't been discussed IIRC. I wonder why you consider your
> >>> solution a workaround? Why should JAX-RS specification define
> >>> another callback for Servlet container, if there is one already
> >>> defined in the Servlet API?
> >>>
> >> I didn't like the fact that I had to share state between the servlet
> >> context listener and the JAX-RS application using a static variable.
> >>
> >> Additionally, If Application.shutdown() existed, this would make it
> >> easier to write integration/acceptance tests using Jersey test
> >> framework (since I can pass an Application instance straight to the
> >> test framework without having to worry about the Servlet API). But
> >> perhaps I'm wandering out of JAX-RS into a Jersey discussion now?
> >
>
> --
> Bill Burke
> JBoss, a division of Red Hat
> http://bill.burkecentral.com