Class: JBackground::Base
- Inherits:
-
Object
- Object
- JBackground::Base
- Includes:
- Singleton
- Defined in:
- lib/j_background/base.rb
Constant Summary collapse
- @@pool_size =
changing pool_size after the first call to #instance has no effect
5
Class Method Summary collapse
Instance Method Summary collapse
-
#execute(*args, &block) ⇒ Object
singleton’s instance method for executing a task.
-
#initialize ⇒ Base
constructor
initializes the thread pool and defines a finalizer that forces all threads to shutdown.
Constructor Details
#initialize ⇒ Base
initializes the thread pool and defines a finalizer that forces all threads to shutdown
12 13 14 |
# File 'lib/j_background/base.rb', line 12 def initialize @thread_pool = java.util.concurrent.Executors.newFixedThreadPool(JBackground::Base.pool_size || 5, JBackgroundThreadFactory.new) end |
Class Method Details
.logger ⇒ Object
39 40 41 |
# File 'lib/j_background/base.rb', line 39 def self.logger @@logger ||= Logger.new(STDOUT) end |
.logger=(value) ⇒ Object
43 44 45 |
# File 'lib/j_background/base.rb', line 43 def self.logger=(value) @@logger = value end |
.pool_size ⇒ Object
31 32 33 |
# File 'lib/j_background/base.rb', line 31 def self.pool_size @@pool_size end |
.pool_size=(value) ⇒ Object
35 36 37 |
# File 'lib/j_background/base.rb', line 35 def self.pool_size=(value) @@pool_size = value end |
Instance Method Details
#execute(*args, &block) ⇒ Object
singleton’s instance method for executing a task
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/j_background/base.rb', line 17 def execute(*args, &block) if block @thread_pool.execute(JBackground::ProcTask.new(block, args)) elsif args[0].is_a? Proc @thread_pool.execute(JBackground::ProcTask.new(*args)) elsif args[0].is_a? JBackground::Task @thread_pool.execute(args[0]) else raise "Invalid task" end end |