Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
1 vote
3 answers
406 views

Singleton MongoClient instance provider

A Java service that connects to MongoDB in production, but opened connection count is too much. It affects on MongoDb performance, so I have come up with a solution that provides only one ...
fuat's user avatar
  • 162
2 votes
0 answers
157 views

SharedPreferences singleton wrapper

I was wondering wether my implementation of the PreferenceService below is thread safe or could cause memory leaks. Android Studio gives me the warning "Do not place Android context classes in ...
nullmn's user avatar
  • 121
1 vote
1 answer
103 views

Using enum for singleton implementations to choose way of doing something

I have this service that reads emails from a mailbox as they come and I want to extract its contents in a map structure. For now I am interested only in the actual email (no images or attachments). I ...
Andreas Andreou's user avatar
4 votes
3 answers
7k views

Simple Publisher Subscriber in Java

I am new to Java and had some difficulty creating this simple Publisher Subscriber class. It finally seems to be working and I wanted to check if I have been following best practices and see if there ...
KNejad's user avatar
  • 171
0 votes
2 answers
1k views

Storing singleton instances in a generic utils class

In one of my java projects I use singletons a lot and I was looking for a way to reduce repeating code. I made a SingletonUtils class that accepts a class and ...
JWCompDev's user avatar
  • 135
3 votes
1 answer
2k views

Implementation of an OkHttp singleton for Android

I'm new to Android programming. I am going to make lots of HTTP requests: 500, 1k, 2k, 10k. I have tried to create a singleton class for OkHttp. I wrote this: ...
Castiel's user avatar
  • 33
3 votes
1 answer
3k views

Attempting to make my properties an enum based singleton

I was attempting to implement my first singleton using an enum, was a bit of a struggle for me and I'm not sure if its right and more importantly thread safe? Property provider enum: ...
symon's user avatar
  • 161
3 votes
1 answer
4k views

Static class for constants with reference to java resources

I want to store the colors I use in the colors.xml file. In addition to using them in an xml-layout, I also want to use these colors in my Java code, when drawing ...
MWB's user avatar
  • 143
0 votes
2 answers
295 views

Create another Singleton object from a Singleton class

I want to create a singleton object of a third party caching library (ThirdPartyKVStore). But I don't want to reference this class all over the place from where I ...
Pankaj's user avatar
  • 101
0 votes
3 answers
6k views

Java Singleton getter/setter

I've created working setters/getters for an application, that will use a few different classes. This classes will use one class, that will store all data. I know, when I will use a standard ...
Fangir's user avatar
  • 53
1 vote
1 answer
1k views

Singleton with a volatile and synchronized instance

I created a singleton to have a unique instance of ExecutorService in my application. I whould like to know which is the better of the two classes below. First one : ...
Eloise's user avatar
  • 113
1 vote
2 answers
4k views

Java MongoDB client as a singleton

Is below code a valid Singleton design pattern for Mongodb in Java? Please suggest any improvements. ...
Dheemanth Bhat's user avatar
5 votes
1 answer
1k views

Singletons with eager and lazy instantiation

I've found more than one implementation of the Singleton Pattern in Java (more like 5-6). I want to know if both of the following snippets of code (written by me) are valid implementations of ...
ovidiu-miu's user avatar
3 votes
1 answer
3k views

Log4j Singleton

I'm trying to design and develop a singleton class that will handle resolution and configuration of log4j (not log4j2). The basic idea is to have a single class, reusable in any application, that ...
lincolnadym's user avatar
1 vote
1 answer
124 views

Is this a good and simple example for Singleton Pattern [closed]

This is a scenario where we keep a single instance(as in Singleton Pattern) to get the configuration of an application. Below is the main class and i set values to the configuarion values here and ...
Harsha Jayamanna's user avatar

15 30 50 per page