Skip to content

Commit 09df063

Browse files
committed
Thread pool at_exit stores id and gets from ObjectSpace when not
JRuby.""
1 parent b254942 commit 09df063

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

lib/concurrent/executor/executor.rb

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,27 @@ def auto_terminate?
6868

6969
def enable_at_exit_handler!(opts = {})
7070
if opts.fetch(:stop_on_exit, true)
71-
# without this the application may fail to exit
7271
@auto_terminate = true
73-
this = self
74-
at_exit { this.kill if Concurrent.auto_terminate_all_executors? }
72+
if RUBY_PLATFORM == 'java'
73+
create_java_at_exit_handler!(self)
74+
else
75+
create_ruby_at_exit_handler!(self.object_id)
76+
end
77+
end
78+
end
79+
80+
def create_ruby_at_exit_handler!(id)
81+
at_exit do
82+
if Concurrent.auto_terminate_all_executors?
83+
this = ObjectSpace._id2ref(id)
84+
this.kill if this
85+
end
86+
end
87+
end
88+
89+
def create_java_at_exit_handler!(this)
90+
at_exit do
91+
this.kill if Concurrent.auto_terminate_all_executors?
7592
end
7693
end
7794
end

0 commit comments

Comments
 (0)