Made PersistenceManager thread safe
Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
parent
d913c31977
commit
fecafaf6c7
Binary file not shown.
|
@ -1,20 +1,28 @@
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Persistence manager using the Singleton pattern.
|
* Persistence manager using the Singleton pattern.
|
||||||
*/
|
*/
|
||||||
public class PersistenceManager
|
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.
|
* Returns an instance of the persistence manager.
|
||||||
* @return instance
|
* @return instance
|
||||||
*/
|
*/
|
||||||
|
@Contract(pure = true)
|
||||||
public static PersistenceManager getInstance()
|
public static PersistenceManager getInstance()
|
||||||
{
|
{
|
||||||
if (instance == null) {
|
|
||||||
instance = new PersistenceManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue