Use Java-21 virtual threads

This commit is contained in:
Michael Lipp 2024-08-10 10:41:50 +00:00
parent 82eb6671a3
commit bef47b308d
6 changed files with 15 additions and 17 deletions

View file

@ -85,7 +85,7 @@ public class K8sObserver<O extends KubernetesObject,
api = new GenericKubernetesApi<>(objectClass, objectListClass,
context.getGroup(), context.getPreferredVersion(),
context.getResourcePlural(), client);
thread = new Thread(() -> {
thread = Thread.ofVirtual().unstarted(() -> {
try {
logger.config(() -> "Watching " + context.getResourcePlural()
+ " (" + context.getPreferredVersion() + ")"
@ -100,7 +100,7 @@ public class K8sObserver<O extends KubernetesObject,
while (changed.hasNext()) {
handler.accept(client, changed.next());
}
} catch (ApiException e) {
} catch (ApiException | RuntimeException e) {
logger.log(Level.FINE, e, () -> "Problem watching"
+ " (will retry): " + e.getMessage());
delayRestart(startedAt);
@ -117,7 +117,6 @@ public class K8sObserver<O extends KubernetesObject,
}
}
});
thread.setDaemon(true);
}
@SuppressWarnings("PMD.AvoidLiteralsInIfCondition")