Minor fixes

This commit is contained in:
Andrew Golovashevich 2025-03-27 01:53:29 +03:00
parent 024ddef803
commit 3f75db556c
2 changed files with 11 additions and 12 deletions

View File

@ -5,15 +5,10 @@ val someStmt = PreparedStatementsCompilationPhantomCache("SELECT * FROM sqlite_m
fun main() {
for (i in 0..1000) {
DriverManager.getConnection("jdbc:sqlite::memory:").use { connection ->
someStmt.preparedStatementForConnection(connection).use { ps ->
ps.executeQuery().use { rs ->
while (rs.next()) {
println(rs.getString(0))
}
}
}
}
val connection = DriverManager.getConnection("jdbc:sqlite::memory:")
val ps = someStmt.preparedStatementForConnection(connection)
val rs = ps.executeQuery();
connection.close()
System.gc()
}
}

View File

@ -26,7 +26,8 @@ class _PhantomCacheCleanup {
@NotNull
private static Thread _createThread() {
if (_PhantomCacheCleanup._isVirtualThreadsSupported() && !System.getProperty(_PhantomCacheCleanup._virtualThreadProperty).equalsIgnoreCase("false")) {
final String useVirtualSetting = System.getProperty(_PhantomCacheCleanup._virtualThreadProperty);
if (_PhantomCacheCleanup._isVirtualThreadsSupported() && (useVirtualSetting != null && !useVirtualSetting.equalsIgnoreCase("false"))) {
return _PhantomCacheCleanup._startVirtualThread();
} else {
return _PhantomCacheCleanup._startVirtualThread();
@ -58,7 +59,7 @@ class _PhantomCacheCleanup {
@NotNull
private static Thread _startVirtualThread() {
final var b = Thread.ofVirtual();
final Thread.Builder.OfVirtual b = Thread.ofVirtual();
b.name(_PhantomCacheCleanup._threadName);
b.inheritInheritableThreadLocals(false);
return b.start(new CleanupRoutine());
@ -72,7 +73,10 @@ class _PhantomCacheCleanup {
// (Thread.currentThread() as? InnocuousThread)?.eraseThreadLocals()
try {
((CleanablePhantomReference<?>) _PhantomCacheCleanup._referenceQueue.remove(60 * 60)).cleanup();
final CleanablePhantomReference<?> cleanableRef = ((CleanablePhantomReference<?>) _PhantomCacheCleanup._referenceQueue.remove(60 * 60));
if (cleanableRef == null)
continue;
cleanableRef.cleanup();
} /* catch (_: LinkageError) {
return
} */ catch (InterruptedException e) {