No commit activity in last 3 years
No release in over 3 years
A wrapper for using Java's Thread Pools for asynchronous tasks
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

j_background¶ ↑

A JRuby library utilizing Java’s concurrency package to create a fixed sized thread pool capable of executing tasks asynchronously.

Useful for long-running tasks to be executed outside of the the Request/Response cycle of a Rails application.

Using With Rails¶ ↑

Please remember that ActiveRecord connections may be closed if you pass an AR model into a background task. It is recommended to pass the id and re-query the database inside the task so as everything is thread-safe.

When using inside Rails, it is also recommended to initialize the logger by creating <RAILS_ROOT>/config/initializers/j_background_initializer.rb

JBackground::Base.logger = RAILS_DEFAULT_LOGGER
JBackground::Base.pool_size = 5
JBackground::Base.instance # force creation of the pool before using inside a request

Examples¶ ↑

JBackground.execute do
  puts "Hello from Thread #{Thread.current.object_id}" 
end

JBackground.execute('Alan', 'Bob', 'Cory') do |x,y,z| 
  puts "Hello #{x}, #{y}, and #{z}"
end

class ExampleTask < JBackground::Task
  def execute_task
    puts "Hello from ExampleTask" 
  end
end

JBackground.execute(ExampleTask.new)

Copyright © 2009 Cory Osborn. See LICENSE for details.