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() { fun main() {
for (i in 0..1000) { for (i in 0..1000) {
DriverManager.getConnection("jdbc:sqlite::memory:").use { connection -> val connection = DriverManager.getConnection("jdbc:sqlite::memory:")
someStmt.preparedStatementForConnection(connection).use { ps -> val ps = someStmt.preparedStatementForConnection(connection)
ps.executeQuery().use { rs -> val rs = ps.executeQuery();
while (rs.next()) { connection.close()
println(rs.getString(0))
}
}
}
}
System.gc() System.gc()
} }
} }

View File

@ -26,7 +26,8 @@ class _PhantomCacheCleanup {
@NotNull @NotNull
private static Thread _createThread() { 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(); return _PhantomCacheCleanup._startVirtualThread();
} else { } else {
return _PhantomCacheCleanup._startVirtualThread(); return _PhantomCacheCleanup._startVirtualThread();
@ -58,7 +59,7 @@ class _PhantomCacheCleanup {
@NotNull @NotNull
private static Thread _startVirtualThread() { private static Thread _startVirtualThread() {
final var b = Thread.ofVirtual(); final Thread.Builder.OfVirtual b = Thread.ofVirtual();
b.name(_PhantomCacheCleanup._threadName); b.name(_PhantomCacheCleanup._threadName);
b.inheritInheritableThreadLocals(false); b.inheritInheritableThreadLocals(false);
return b.start(new CleanupRoutine()); return b.start(new CleanupRoutine());
@ -72,7 +73,10 @@ class _PhantomCacheCleanup {
// (Thread.currentThread() as? InnocuousThread)?.eraseThreadLocals() // (Thread.currentThread() as? InnocuousThread)?.eraseThreadLocals()
try { 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) { } /* catch (_: LinkageError) {
return return
} */ catch (InterruptedException e) { } */ catch (InterruptedException e) {