All Questions
4 questions
19
votes
6
answers
8k
views
Is utilizing a singleton for a cache an antipattern?
I'm currently writing an MVC application and I need a class that can:
A: get, add and remove data(specifically a TreeSet of sorted strings that I want stored in memory, but I doubt the data itself is ...
3
votes
1
answer
312
views
If a class has no instance specific data is it okay to make it a singleton?
Let's say I have the following Java code:
public class ObjectConsumer implements Consumer<Object> {
@Override
public void accept(Object o) {
System.out.println("Accepted " + o);
...
2
votes
2
answers
2k
views
Joshua Bloch Enum Singleton and Third Party APIs
In the book Effective Java he give the best Singleton pattern implementation in his, that is implement by a Enum. I have doubt to how to implement this pattern with a third party API.
I'm using an ...
1
vote
6
answers
8k
views
How to change the state of a singleton in runtime
Consider I am going to write a simple file based logger AppLogger to be used in my apps, ideally it should be a singleton so I can call it via
public class AppLogger {
public static String file = ...