Skip to content

Commit e87d8a7

Browse files
authored
Apply lazy load on MySqlAuthProvider instances (#127)
Motivation: Better load singleton instances when we really need it. Modifications: Apply Lazy Load on AuthProviders. Results: Less memory footprint.
1 parent 269371d commit e87d8a7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/main/java/io/asyncer/r2dbc/mysql/authentication/CachingSha2FastAuthProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public byte[] authentication(@Nullable CharSequence password, byte[] salt, CharC
6161

6262
@Override
6363
public MySqlAuthProvider next() {
64-
return CachingSha2FullAuthProvider.INSTANCE;
64+
return CachingSha2FullAuthProvider.getInstance();
6565
}
6666

6767
@Override

src/main/java/io/asyncer/r2dbc/mysql/authentication/CachingSha2FullAuthProvider.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
*/
3131
final class CachingSha2FullAuthProvider implements MySqlAuthProvider {
3232

33-
static final CachingSha2FullAuthProvider INSTANCE = new CachingSha2FullAuthProvider();
33+
static CachingSha2FullAuthProvider getInstance() {
34+
return LazyHolder.INSTANCE;
35+
}
3436

3537
@Override
3638
public boolean isSslNecessary() {
@@ -60,4 +62,8 @@ public String getType() {
6062
}
6163

6264
private CachingSha2FullAuthProvider() { }
65+
66+
private static class LazyHolder {
67+
private static final CachingSha2FullAuthProvider INSTANCE = new CachingSha2FullAuthProvider();
68+
}
6369
}

0 commit comments

Comments
 (0)