Module: Concurrent::JavaExecutor
- Includes:
- Executor
- Included in:
- JavaSingleThreadExecutor, JavaThreadPoolExecutor
- Defined in:
- lib/concurrent/executor/executor.rb
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) ⇒ 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.
161 162 163 164 |
# File 'lib/concurrent/executor/executor.rb', line 161 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 executor is not running.
216 217 218 219 |
# File 'lib/concurrent/executor/executor.rb', line 216 def kill @executor.shutdownNow nil end |
#post(*args) { ... } ⇒ Boolean
Submit a task to the executor for asynchronous processing.
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/concurrent/executor/executor.rb', line 144 def post(*args) raise ArgumentError.new('no block given') unless block_given? if running? @executor.submit{ yield(*args) } true else false end rescue Java::JavaUtilConcurrent::RejectedExecutionException => ex raise RejectedExecutionError end |
#running? ⇒ Boolean
Is the executor running?
169 170 171 |
# File 'lib/concurrent/executor/executor.rb', line 169 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 executor is not running.
207 208 209 210 |
# File 'lib/concurrent/executor/executor.rb', line 207 def shutdown @executor.shutdown nil end |
#shutdown? ⇒ Boolean
Is the executor shutdown?
187 188 189 |
# File 'lib/concurrent/executor/executor.rb', line 187 def shutdown? @executor.isShutdown || @executor.isTerminated end |
#shuttingdown? ⇒ Boolean
Is the executor shuttingdown?
176 177 178 179 180 181 182 |
# File 'lib/concurrent/executor/executor.rb', line 176 def shuttingdown? if @executor.respond_to? :isTerminating @executor.isTerminating else false end end |
#wait_for_termination(timeout) ⇒ 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.
200 201 202 |
# File 'lib/concurrent/executor/executor.rb', line 200 def wait_for_termination(timeout) @executor.awaitTermination(1000 * timeout, java.util.concurrent.TimeUnit::MILLISECONDS) end |