users@jersey.java.net

[Jersey] Re: Servlet.Init() For Jersey REST Service

From: juminoz <juminoz_at_hotmail.com>
Date: Thu, 23 Jun 2011 08:52:32 -0700 (PDT)

Martin,

Here's what I'm trying to do.

1) Initialize connection to datasource at start up. This could be a database
or even connecting to JMS.
2) For every request to the servlet, it should reuse these connection
resources rather than creating a new one.

For a regular servlet, you can do all these in init method and store the
reference in memory. For Jersey servlet, this doesn't seem to be an option.

Potentially, I can utilize web server connection pool for these resource and
grab connection from the pool instead of connecting every time
(authentication is very expensive), but I would expect to be able to do
similar thing without having to use connection pool.

Why isn't the resource create once and reused? Why should the resource class
constructor be called every time. I know REST is supposed to be stateless
and all, but why go through a potentially expensive call to create a new
resource for each call to the servlet. If a resource must be created per
request then what would be the best way to store some connection objects
without resorting for connection pool provided by web/app server?

Thanks,
Jack

--
View this message in context: http://jersey.576304.n2.nabble.com/Servlet-Init-For-Jersey-REST-Service-tp6507144p6508806.html
Sent from the Jersey mailing list archive at Nabble.com.