Skip to content

Commit 4be5c85

Browse files
committed
Hide JavaDaemonThreadFactory and make YARD happy
1 parent 94dfbc1 commit 4be5c85

File tree

8 files changed

+29
-32
lines changed

8 files changed

+29
-32
lines changed

lib/concurrent-ruby/concurrent/configuration.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def self.global_logger=(value)
115115
# Disables AtExit handlers including pool auto-termination handlers.
116116
# When disabled it will be the application programmer's responsibility
117117
# to ensure that the handlers are shutdown properly prior to application
118-
# exit by calling {AtExit.run} method.
118+
# exit by calling `AtExit.run` method.
119119
#
120120
# @note this option should be needed only because of `at_exit` ordering
121121
# issues which may arise when running some of the testing frameworks.
@@ -125,9 +125,9 @@ def self.global_logger=(value)
125125
# @note This method should *never* be called
126126
# from within a gem. It should *only* be used from within the main
127127
# application and even then it should be used only when necessary.
128-
# @see AtExit
128+
#
129129
def self.disable_at_exit_handlers!
130-
AtExit.enabled = false
130+
AT_EXIT.enabled = false
131131
end
132132

133133
# Global thread pool optimized for short, fast *operations*.

lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ def ns_auto_terminate?
125125
def ns_auto_terminate=(value)
126126
case value
127127
when true
128-
AtExit.add(self) { terminate_at_exit }
128+
AT_EXIT.add(self) { terminate_at_exit }
129129
@auto_terminate = true
130130
when false
131-
AtExit.delete(self)
131+
AT_EXIT.delete(self)
132132
@auto_terminate = false
133133
else
134134
raise ArgumentError

lib/concurrent-ruby/concurrent/executor/cached_thread_pool.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class CachedThreadPool < ThreadPoolExecutor
3737
#
3838
# @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool--
3939
def initialize(opts = {})
40-
defaults = { idletime: DEFAULT_THREAD_IDLETIMEOUT }
40+
defaults = { idletime: DEFAULT_THREAD_IDLETIMEOUT }
4141
overrides = { min_threads: 0,
4242
max_threads: DEFAULT_MAX_POOL_SIZE,
4343
max_queue: DEFAULT_MAX_QUEUE_SIZE }
@@ -52,10 +52,9 @@ def ns_initialize(opts)
5252
super(opts)
5353
if Concurrent.on_jruby?
5454
self.auto_terminate = opts.fetch(:auto_terminate, true)
55-
@max_queue = 0
56-
@executor = java.util.concurrent.Executors.newCachedThreadPool(
57-
Concurrent::DaemonThreadFactory.new(self.auto_terminate?)
58-
)
55+
@max_queue = 0
56+
@executor = java.util.concurrent.Executors.newCachedThreadPool(
57+
DaemonThreadFactory.new(self.auto_terminate?))
5958
@executor.setRejectedExecutionHandler(FALLBACK_POLICY_CLASSES[@fallback_policy].new)
6059
@executor.setKeepAliveTime(opts.fetch(:idletime, DEFAULT_THREAD_IDLETIMEOUT), java.util.concurrent.TimeUnit::SECONDS)
6160
end

lib/concurrent-ruby/concurrent/executor/java_daemon_thread_factory.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.

lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,27 @@ def ns_initialize(opts)
116116
idletime,
117117
java.util.concurrent.TimeUnit::SECONDS,
118118
queue,
119-
Concurrent::DaemonThreadFactory.new(self.auto_terminate?),
119+
DaemonThreadFactory.new(self.auto_terminate?),
120120
FALLBACK_POLICY_CLASSES[@fallback_policy].new)
121121

122122
end
123123
end
124+
125+
class DaemonThreadFactory
126+
# hide include from YARD
127+
send :include, java.util.concurrent.ThreadFactory
128+
129+
def initialize(daemonize = true)
130+
@daemonize = daemonize
131+
end
132+
133+
def newThread(runnable)
134+
thread = java.util.concurrent.Executors.defaultThreadFactory().newThread(runnable)
135+
thread.setDaemon(@daemonize)
136+
return thread
137+
end
138+
end
139+
140+
private_constant :DaemonThreadFactory
124141
end
125142
end

lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module Concurrent
55

66
if Concurrent.on_jruby?
77
require 'concurrent/executor/java_thread_pool_executor'
8-
require 'concurrent/executor/java_daemon_thread_factory'
98
end
109

1110
ThreadPoolExecutorImplementation = case

lib/concurrent-ruby/concurrent/utility/at_exit.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def runner
9191

9292
private_constant :AtExitImplementation
9393

94-
# @see AtExitImplementation
9594
# @!visibility private
96-
AtExit = AtExitImplementation.new.install
95+
AT_EXIT = AtExitImplementation.new.install
9796
end

spec/concurrent/configuration_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module Concurrent
2424
expect(Concurrent.global_fast_executor).to receive(:kill).at_least(:once).with(no_args)
2525
expect(Concurrent.global_io_executor).to receive(:kill).at_least(:once).with(no_args)
2626
expect(Concurrent.global_timer_set).to receive(:kill).at_least(:once).with(no_args)
27-
Concurrent::AtExit.run
27+
Concurrent::AT_EXIT.run
2828
end
2929
end
3030
end

0 commit comments

Comments
 (0)