Tagged Questions
21
votes
8answers
1k views
Is my code a 'safe' singleton?
I was wondering if my code will produce a true singleton. I am creating an Android app, and all activities should access my API through one instance of the SyncApi class.
public class Api {
...
6
votes
3answers
481 views
Static methods or singleton?
I have class that handles HTTP requests:
public final class RestHttpClient {
/*there is no fields*/
/**
* @param mhttp - HTTP request that need to send
* @return HttpResponse, ...
4
votes
3answers
141 views
Is this correct implementation of singleton using enum?
public class Item3 {
public static void main(String[] args) {
Singleton s=Singleton.Single.INSTANCE.getInstance();
Singleton s2=Singleton.Single.INSTANCE.getInstance();
...
4
votes
1answer
194 views
Pubsub implementation using a Singleton
Is using a singleton to represent a Publish-subscribe message system a bad design choice?
Background
Im thinking about writing a pubsub implementation (using the singleton pattern) to allow for ...
4
votes
1answer
1k views
Singleton class extending a parent class to utilise shared functionality
I have a singleton class which extends from an abstract java class. Two singleton classes extend from ItemImageThreadManager, the reason for this is to use shared scheduling functionality. A thread is ...
2
votes
5answers
421 views
Request for Comments: Singleton pattern implemented in Java
I have several utility classes who should only ever have one instance in memory, such as LogHelper, CacheHelper, etc. One instance to rule them all.
I've never implemented Singleton in Java before, ...
2
votes
1answer
421 views
Is this a good implementation of a thread-safe singleton using the observer pattern?
I need a singleton that can safely operate in a multi-thread environment. Threading and concurrency is new to me, so I'm not sure if this implementation holds. Take a look:
public class ...
0
votes
2answers
159 views
Singleton interface in Java
I've created a singleton by means of an interface. I don't want to make a thing with getInstance() etc because I don't care about inheritance, and it's redundant and non-declarative.
Are there ...
0
votes
0answers
43 views
Abstract class which uses a abstract factory -> New implementation with Singleton
I have a abstract class which is extended by many many other classes:
What I have done:
public abstract class AbstractActionHandler {
protected WorkItem currentWI;
protected String status;
...