Skip to content

BITMAG-1248 Replace java.util.Timer with ScheduledExecutorService + virtual threads - #97

Open
Knud-Aage wants to merge 4 commits into
masterfrom
BITMAG-1248-use-scheduled-executor-service
Open

BITMAG-1248 Replace java.util.Timer with ScheduledExecutorService + virtual threads #97
Knud-Aage wants to merge 4 commits into
masterfrom
BITMAG-1248-use-scheduled-executor-service

Conversation

@Knud-Aage

Copy link
Copy Markdown
Contributor

java.util.Timer runs every scheduled task on a single shared thread, and an uncaught exception in any TimerTask silently kills that thread — every other job scheduled on it stops firing with no error surfaced. This replaces all Timer/TimerTask usage with a new
ScheduledVirtualThreadExecutor.
ScheduledVirtualThreadExecutor (bitrepository-core) pairs a single-thread ScheduledExecutorService "ticker" — which only decides when to fire — with a virtual-thread-per-task executor that actually runs each firing. This means:

  • a slow or blocking task run can't delay the next scheduled tick
  • an uncaught exception in one task run is logged and only kills that one virtual thread, not the scheduler
  • tasks no longer compete for a small bounded thread pool
    Converted call sites (TimerTask → Runnable, Timer → ScheduledVirtualThreadExecutor):
  • TimerBasedScheduler (workflow scheduling)
  • AuditTrailCollector / LocalAuditTrailPreserver
  • CollectionBasedConversationMediator (conversation cleanup)
  • StatusCollector (monitoring service)
    JobScheduler gained a shutdown() method, threaded through WorkflowManager.shutdown() and called from IntegrityServiceManager and Pillar.close(), so the scheduler's executors are actually released on shutdown instead of leaking threads.

Added ScheduledVirtualThreadExecutorTest and TimerBasedSchedulerTest to cover the new scheduling behavior.

  An uncaught exception in any TimerTask silently kills the whole timer thread.
  ScheduledExecutorService is the recommended replacement, and combined with virtual threads it lets each firing run independently without needing a bounded thread pool.
@Knud-Aage
Knud-Aage requested a review from ole-v-v August 25, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant