Module: Concurrent::JavaExecutor
- Includes:
- Executor
- Included in:
- JavaSingleThreadExecutor, JavaThreadPoolExecutor
- Defined in:
- lib/concurrent/executor/executor.rb
Constant Summary collapse
- FALLBACK_POLICIES =
The set of possible fallback policies that may be set at thread pool creation.
{ abort: java.util.concurrent.ThreadPoolExecutor::AbortPolicy, discard: java.util.concurrent.ThreadPoolExecutor::DiscardPolicy, caller_runs: java.util.concurrent.ThreadPoolExecutor::CallerRunsPolicy }.freeze
Instance Attribute Summary
Attributes included from Executor
Instance Method Summary collapse
-
#<<(task) ⇒ self
Submit a task to the executor for asynchronous processing.
-
#kill ⇒ Object
Begin an immediate shutdown.
-
#post(*args) { ... } ⇒ Boolean
Submit a task to the executor for asynchronous processing.
-
#running? ⇒ Boolean
Is the executor running?.
-
#shutdown ⇒ Object
Begin an orderly shutdown.
-
#shutdown? ⇒ Boolean
Is the executor shutdown?.
-
#shuttingdown? ⇒ Boolean
Is the executor shuttingdown?.
-
#wait_for_termination(timeout = nil) ⇒ Boolean
Block until executor shutdown is complete or until ‘timeout` seconds have passed.
Methods included from Executor
Instance Method Details
#<<(task) ⇒ self
Submit a task to the executor for asynchronous processing.
266 267 268 269 |
# File 'lib/concurrent/executor/executor.rb', line 266 def <<(task) post(&task) self end |
#kill ⇒ Object
Begin an immediate shutdown. In-progress tasks will be allowed to complete but enqueued tasks will be dismissed and no new tasks will be accepted. Has no additional effect if the thread pool is not running.
307 308 309 310 |
# File 'lib/concurrent/executor/executor.rb', line 307 def kill @executor.shutdownNow nil end |
#post(*args) { ... } ⇒ Boolean
Submit a task to the executor for asynchronous processing.
255 256 257 258 259 260 261 262 263 |
# File 'lib/concurrent/executor/executor.rb', line 255 def post(*args, &task) raise ArgumentError.new('no block given') unless block_given? return handle_fallback(*args, &task) unless running? executor_submit = @executor.java_method(:submit, [Runnable.java_class]) executor_submit.call { yield(*args) } true rescue Java::JavaUtilConcurrent::RejectedExecutionException raise RejectedExecutionError end |
#running? ⇒ Boolean
Is the executor running?
272 273 274 |
# File 'lib/concurrent/executor/executor.rb', line 272 def running? ! (shuttingdown? || shutdown?) end |
#shutdown ⇒ Object
Begin an orderly shutdown. Tasks already in the queue will be executed, but no new tasks will be accepted. Has no additional effect if the thread pool is not running.
301 302 303 304 |
# File 'lib/concurrent/executor/executor.rb', line 301 def shutdown @executor.shutdown nil end |
#shutdown? ⇒ Boolean
Is the executor shutdown?
286 287 288 |
# File 'lib/concurrent/executor/executor.rb', line 286 def shutdown? @executor.isShutdown || @executor.isTerminated end |
#shuttingdown? ⇒ Boolean
Is the executor shuttingdown?
277 278 279 280 281 282 283 |
# File 'lib/concurrent/executor/executor.rb', line 277 def shuttingdown? if @executor.respond_to? :isTerminating @executor.isTerminating else false end end |
#wait_for_termination(timeout = nil) ⇒ Boolean
Does not initiate shutdown or termination. Either ‘shutdown` or `kill` must be called before this method (or on another thread).
Block until executor shutdown is complete or until ‘timeout` seconds have passed.
291 292 293 294 295 296 297 298 |
# File 'lib/concurrent/executor/executor.rb', line 291 def wait_for_termination(timeout = nil) if timeout.nil? ok = @executor.awaitTermination(60, java.util.concurrent.TimeUnit::SECONDS) until ok true else @executor.awaitTermination(1000 * timeout, java.util.concurrent.TimeUnit::MILLISECONDS) end end |