Singleton or getSingletons() while implementing Singleton Resources in Jersey?

Up vote 0 down vote favorite share g+ share fb share tw.

I have a resource to be exposed as Restful WS. If I have to make it Singleton, what is the preferred and advised way: 1 . Annotating the resource class using @Singleton Or 2 .

Implementing the getSingletons() method in my Application class implementation and instantiating the resource there like public class RestApplication extends Application { private Set singletons = new HashSet(); public RestApplication() { singletons. Add(new PlayerResource()); } @Override public Set> getClasses() { return null; } @Override public Set getSingletons() { return singletons; } } I tried both ways and realised that both of them creates a singleton instance of the resource class, PlayerResource in this case. Java jersey link|improve this question edited Jun 29 '11 at 11:45Tim Cooper25k62349 asked Jun 29 '11 at 11:43Dhanush Gopinath26918 95% accept rate.

A similar question on Singletons was asked here as to the best implementation. Personally I would explicitly code the singleton pattern than use an annotation. See here: stackoverflow.com/questions/427902/java-... – adamjmarkham Jun 29 '11 at 12:19 @AdamJMTech - my question is specific to Jersey/JAX-RS.

Just wanted to know which on of them is the preferred way. Or what advantage either of them brings in. – Dhanush Gopinath Jun 29 '11 at 12:35.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions