Made PersistenceManager thread safe

Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
Jim Martens 2017-05-19 11:37:00 +02:00
parent d913c31977
commit fecafaf6c7
2 changed files with 13 additions and 5 deletions

Binary file not shown.

View File

@ -1,20 +1,28 @@
import org.jetbrains.annotations.Contract;
/**
* Persistence manager using the Singleton pattern.
*/
public class PersistenceManager
{
private static PersistenceManager instance = null;
private final static PersistenceManager instance;
static {
try {
instance = new PersistenceManager();
}
catch (Throwable e) {
throw new RuntimeException(e.getMessage());
}
}
/**
* Returns an instance of the persistence manager.
* @return instance
*/
@Contract(pure = true)
public static PersistenceManager getInstance()
{
if (instance == null) {
instance = new PersistenceManager();
}
return instance;
}