mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-15 14:59:25 +00:00
Reformat rest of the design patterns - Issue #224
This commit is contained in:
@@ -2,23 +2,22 @@ package com.iluwatar.lazy.loading;
|
||||
|
||||
/**
|
||||
*
|
||||
* Same as HolderNaive but with added synchronization.
|
||||
* This implementation is thread safe, but each {@link #getHeavy()}
|
||||
* call costs additional synchronization overhead.
|
||||
* Same as HolderNaive but with added synchronization. This implementation is thread safe, but each
|
||||
* {@link #getHeavy()} call costs additional synchronization overhead.
|
||||
*
|
||||
*/
|
||||
public class HolderThreadSafe {
|
||||
|
||||
private Heavy heavy;
|
||||
|
||||
public HolderThreadSafe() {
|
||||
System.out.println("HolderThreadSafe created");
|
||||
}
|
||||
|
||||
public synchronized Heavy getHeavy() {
|
||||
if (heavy == null) {
|
||||
heavy = new Heavy();
|
||||
}
|
||||
return heavy;
|
||||
}
|
||||
private Heavy heavy;
|
||||
|
||||
public HolderThreadSafe() {
|
||||
System.out.println("HolderThreadSafe created");
|
||||
}
|
||||
|
||||
public synchronized Heavy getHeavy() {
|
||||
if (heavy == null) {
|
||||
heavy = new Heavy();
|
||||
}
|
||||
return heavy;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user