users@jersey.java.net

[Jersey] Where to put the application logic of a Jersey server

From: ax487 <ax487_at_gmx.de>
Date: Fri, 13 Feb 2015 14:03:10 +0100

Hello all,

I have been using Jersey to write the front end of a REST service, and I
am quite pleased with the API / performance so far.

My server is designed to take requests, perform some calculations and
provide a set of results for each request. I need one place (I guess a
singleton class) to gather the requests, perform the computations (using
some worker threads) and provide the results. I guess that due to the
presence of a large number of worker threads I will have to put some
synchronization in place as well.

My question is: How can I make sure that such a class is constructed
before the server starts answering queries? I am writing a
WebApplication and not an ordinary java application so there is no
`main()` method which would be the obvious place. I tried extending the
`javax.ws.rs.core.Application` which acts as a resource configurator but
this class seems to be constructed multiple times by the ClassLoader.
Are the singletons which I can register in the application guaranteed to
be constructed in time?

ax487