Saturday 15 June 2013

multithreading - How to use Ruby Java Bridge with threads (Sidekiq) -



multithreading - How to use Ruby Java Bridge with threads (Sidekiq) -

i wrote little java class read embedded images xls file , need utilize in background process (using sidekiq) of ruby on rails application. looks there issues threading jvm throws error guarantee(get_thread() == thread) failed: must same thread, quickly when sidekiq process starts executing method rjb used.

this how set up.

i wrote initializer set the rjb

require 'rjb' jars = dir.glob("#{rails.root}/lib/java_libs/*.jar").join(':') rjb::load(jars) excel_image_reader = rjb::import('tools.imagereader')

then utilize in background process

def get_excel_images p 'starting images' images = [] image_reader = excel_image_reader.new(@excel_path) image_reader.get_file_names.each |file_name| images << attachment.new_from_bytes(image_reader.get_file(file_name), file_name) end images end

but method started execute jvm throws exception. here log sidekiq.

2014-10-30t09:47:02z 11748 tid-17e7qk info: running in ruby 2.1.1p76 (2014-02-24 revision 45161) [i686-linux] 2014-10-30t09:47:02z 11748 tid-17e7qk info: see license , lgpl-3.0 licensing details. 2014-10-30t09:47:02z 11748 tid-17e7qk info: starting processing, nail ctrl-c stop 2014-10-30t09:47:31z 11748 tid-19393k sidekiq::extensions::delayedclass jid-08eac9ed686f8d6146cda67f info: start "starting images" # # fatal error has been detected java runtime environment: # # internal error (threadlocalstorage.cpp:60), pid=11748, tid=2960567104 # guarantee(get_thread() == thread) failed: must same thread, # # jre version: openjdk runtime environment (7.0_65-b32) (build 1.7.0_65-b32) # java vm: openjdk client vm (24.65-b04 mixed mode, sharing linux-x86 ) # derivative: icedtea 2.5.3 # distribution: ubuntu 12.04 lts, bundle 7u71-2.5.3-0ubuntu0.12.04.1 # failed write core dump. core dumps have been disabled. enable core dumping, seek "ulimit -c unlimited" before starting java 1 time again # # error study file more info saved as: # /home/mika/projects/my_project/hs_err_pid11748.log # # if submit bug report, please include # instructions on how reproduce bug , visit: # http://icedtea.classpath.org/bugzilla # aborted (core dumped)

i tried move stuff initializer get_excel_images method didn't have effect. code works if run straight console or through rspec test.

does have ideas how solve this?

i found info rjb github issues https://github.com/arton/rjb/issues/24. looks downgrading ruby 1.9.3 , rjb 1.4.9 might solve issue, not solution since ruby 1.9.3 going receive security patches couple of months more. issue beingness how threads created , how has changed ruby 1.9.3 ruby 2.

after trying many different solutions moved jruby. java interactions work easily.

update:

after suffering year slowness of jruby moved java stuff independent daemon process , communicate daemon through tcp socket using json transmit data. i'm in mri ruby , development feels enjoyable again.

ruby-on-rails multithreading sidekiq rjb

No comments:

Post a Comment