Class VirtualThreadConfigWatcher

java.lang.Object
cloud.opencode.base.config.jdk25.VirtualThreadConfigWatcher
All Implemented Interfaces:
AutoCloseable

public class VirtualThreadConfigWatcher extends Object implements AutoCloseable
Virtual Thread Configuration Watcher 虚拟线程配置监视器

Monitors configuration sources for changes using JDK 25 virtual threads. Provides lightweight, scalable file watching with non-blocking notifications.

使用JDK 25虚拟线程监视配置源的变化。提供轻量级、可扩展的文件监视和非阻塞通知。

Features | 主要功能:

  • Virtual thread-based watching - 基于虚拟线程的监视
  • Non-blocking listener notification - 非阻塞监听器通知
  • Automatic resource cleanup - 自动资源清理
  • Graceful shutdown support - 优雅关闭支持

Usage Examples | 使用示例:

try (VirtualThreadConfigWatcher watcher = new VirtualThreadConfigWatcher()) {
    watcher.addListener(event -> {
        System.out.println("Config changed: " + event.getKey());
        System.out.println("Old: " + event.getOldValue());
        System.out.println("New: " + event.getNewValue());
    });

    watcher.start();

    // Watcher runs in background virtual thread
    // ...application logic...
}
// Auto-closes when try-with-resources exits

JDK 25 Features Used | 使用的JDK 25特性:

  • Thread.startVirtualThread() - Virtual thread creation
  • Lightweight thread scheduling - 轻量级线程调度

Performance | 性能特性:

  • Minimal memory footprint - 最小内存占用
  • Scalable to thousands of watchers - 可扩展到数千个监视器
  • Non-blocking notifications - 非阻塞通知

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Null-safe: Partial (validates inputs) - 空值安全: 部分(验证输入)
Since:
JDK 25, opencode-base-config V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • VirtualThreadConfigWatcher

      public VirtualThreadConfigWatcher()
  • Method Details

    • start

      public void start()
    • addListener

      public void addListener(ConfigListener listener)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable