Skip to content

Commit

Permalink
TP-1222: Make getInstance() thread-safe with double-checked locking (#49
Browse files Browse the repository at this point in the history
)
  • Loading branch information
pativa authored Sep 5, 2022
1 parent fe7c051 commit b022171
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@
*/
public final class JVMGlobalGigaSpacesManager {

private static InMemoryGigaSpacesManager instance;
private static volatile InMemoryGigaSpacesManager instance;

private static InMemoryGigaSpacesManager getInstance() {
if (instance == null) {
instance = new InMemoryGigaSpacesManager();
Runtime.getRuntime().addShutdownHook(new Thread(() -> instance.close()));
synchronized (JVMGlobalGigaSpacesManager.class) {
if (instance == null) {
instance = new InMemoryGigaSpacesManager();
Runtime.getRuntime().addShutdownHook(new Thread(() -> instance.close()));
}
}
}
return instance;
}
Expand Down

0 comments on commit b022171

Please sign in to comment.