Skip to content
Advertisement

Tag: singleton

Having issues calling a decorator method (Java)

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 PokemonGenerator class, that has a method generateRandomPokemon(int level) that picks

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 these initializations so I’m not sure how to fix this aside from using a different Elasticsearch

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 take a

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 it synchronize on? Secondly, why is the following implementation thread safe AND lazy

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: Eager Singleton: Lazy Singleton with inner holder class: Enum Singleton: You should probably stick

Advertisement