Do not use virtual threads for native calls

This commit is contained in:
Andrea Cavalli 2024-11-05 15:55:11 +01:00
parent 72fbd17768
commit 091eda1b50
4 changed files with 5 additions and 9 deletions

View File

@ -118,7 +118,8 @@ public class Main {
grpcServerBuilder.setClient(connection);
CountDownLatch shutdownLatch = new CountDownLatch(1);
Runtime.getRuntime().addShutdownHook(new Thread(shutdownLatch::countDown));
Runtime.getRuntime().addShutdownHook(Thread.ofPlatform()
.name("DB shutdown hook").unstarted(shutdownLatch::countDown));
try (var thrift = thriftServerBuilder.build(); var grpc = grpcServerBuilder.build()) {
thrift.start();

View File

@ -30,7 +30,7 @@ public class TestGrpcLoop {
var col = client.getSyncApi().createColumn("test", ColumnSchema.of(IntList.of(15), ObjectList.of(), true));
var parallelism = 4;
for (int i = 0; i < parallelism; i++) {
var t = new Thread(() -> {
var t = Thread.ofPlatform().daemon().name("test-requests-thread-" + i).start(() -> {
while (true) {
try (var arena = Arena.ofConfined()) {
var delta = client.getSyncApi().put(arena, 0, col,
@ -40,9 +40,6 @@ public class TestGrpcLoop {
}
}
});
t.setDaemon(true);
t.setName("test-requests-thread-" + i);
t.start();
if (i + 1 == parallelism) {
t.join();
}

View File

@ -26,7 +26,7 @@ public class DatabaseTasks implements Closeable {
public synchronized void start() {
if (delayWalFlushConfig.toMillis() > 0) {
this.walFlushThread = Thread.ofVirtual().name("db." + db.getName() + ".tasks.wal.flush").start(() -> {
this.walFlushThread = Thread.ofPlatform().name("db." + db.getName() + ".tasks.wal.flush").start(() -> {
logger.info("Database delayed flush thread is enabled, it will flush the database every %.2f seconds".formatted(delayWalFlushConfig.toMillis() / 1000d));
while (!Thread.interrupted()) {
try {

View File

@ -48,9 +48,7 @@ public class ThriftServer extends Server {
.processor(new Processor<>(handler))
);
var thriftThread = new Thread(server::serve);
thriftThread.setName("Thrift server thread");
this.thriftThread = thriftThread;
this.thriftThread = Thread.ofPlatform().name("Thrift server thread").unstarted(server::serve);
LOG.info("Thrift RocksDB server is listening at " + http2Host + ":" + http2Port);
} catch (TTransportException e) {
throw new IOException("Can't open server socket", e);