Working on a group project that is essentially a text-based Pokemon rip-off. My classmates and I were given a UML to work from so I can’t accept any solutions that would add methods or change their parameters. But essentially the issue we’re running into is this: There is a singleton PokemonGenera…
Tag: singleton
Initializing JestClient when application calls multiple Elasticsearch endpoints
My API currently calls one Elasticsearch endpoint using JestClient. I want to add some functionality that requires calling a second, different Elasticsearch endpoint. How is this possible, when you have to specify the endpoint upon initializing JestClient? My application design uses Singleton classes for thes…
How to create a single instance of object across entire Spring MVC web application?
I have a Spring MVC web application (XML based without annotations). I want to create only one instance of statsDClient object on start of my application and use it across my whole application. I am trying something like below: Later in my controllers I am getting the statsDClient object in the following way:…
In what domain is there a single instance of a Java singleton?
By definition, there can be a single instance of a Java singleton class. Except of course when there’s obviously several, including the same code running on different physical machines, virtual …
Android: Cannot perform this operation because the connection pool has been closed
I was reading through StackOverflow about this question and I still haven’t found a solution. I notice that sometimes, my app throws this error: I have a file called DatabaseHelper.java using this approach to get an instance of it: Then I have methods like this one (that it crashed in the line cursor.mo…
Thread Safe singleton class
I wrote a below Singleton class. I am not sure whether this is thread safe singleton class or not? Can anyone help me with this? Any thoughts on my above Singleton class will be of great help. Updated Code:- I am trying to incorporate Bohemian suggestion in my code. Here is the updated code, I got- Can anyone…
Thread Safe Singletons in Java
The wikipedia article on Singletons mentions a few thread safe ways to implement the structure in Java. For my questions, let’s consider Singletons that have lengthy initialization procedures and are acccessed by many threads at once. Firstly, is this unmentioned method thread-safe, and if so, what does…
Singleton using AtomicReference
Is it correct implementation of lazy-initializing singleton using AtomicReference? If no – what are the possible issues? Answer No, this is bad: Using an AtomicReference is a nice idea, but it won’t work because Java doesn’t have lazy evaluation. The classic post 1.5 singleton methods are: E…
Weblogic 10.3 managed server shared memory object(s)
We are using Oracle Weblogic 10.3 as our application server. We have multiple modules that need to access an Object (contains some HashMaps) that is common for the managed server. This object will be populated via some other process on a daily basis. We do not want to have copies of this in each application, …
singleton pattern in java. lazy initialization
1.is there a flaw with the above implementation of the getInstance method? 2.What is the difference between the two implementations.? I have seen a lot of answers on the singleton pattern in stackoverflow but the question I have posted is to know mainly difference of ‘synchronize’ at method and bl…