Skip to content

Commit

Permalink
Fix DaemonThreadFactory - reuse single Java thread factory
Browse files Browse the repository at this point in the history
* Move defaultThreadFactory call to DaemonThreadFactory#initialize and store
resulting factory in @java_thread_factory
* In DaemonThreadFactory#newThread, use stored factory to generate new threads
instead of creating a new factory each time
  • Loading branch information
obulkin committed Aug 28, 2023
1 parent 1982b92 commit 660f7db
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ class DaemonThreadFactory

def initialize(daemonize = true)
@daemonize = daemonize
@java_thread_factory = java.util.concurrent.Executors.defaultThreadFactory
end

def newThread(runnable)
thread = java.util.concurrent.Executors.defaultThreadFactory().newThread(runnable)
thread = @java_thread_factory.newThread(runnable)
thread.setDaemon(@daemonize)
return thread
end
Expand Down

0 comments on commit 660f7db

Please sign in to comment.