# Getting random threading errors in jruby (1.7.3) & rails 2.3.17 application

**URL:** <https://www.ruby-forum.com/t/getting-random-threading-errors-in-jruby-1-7-3-rails-2-3-17-application/230205>\
**Category:** Rails\
**Created:** [June 4, 2014, 4:54pm UTC](https://www.ruby-forum.com/t/getting-random-threading-errors-in-jruby-1-7-3-rails-2-3-17-application/230205 "2014-06-04T16:54:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason\_sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7993a0/32.png) [@jason\_sam](https://www.ruby-forum.com/u/jason_sam)\
**Post date:** [June 4, 2014, 4:54pm UTC](https://www.ruby-forum.com/t/getting-random-threading-errors-in-jruby-1-7-3-rails-2-3-17-application/230205/1 "2014-06-04T16:54:22Z")

</div>

I am running jruby (1.7.3) & rails 2.3.17 application whose apis are  
exposed to outside app. When I add “config.threadsafe!” in my  
development.rb/production.rb & hit lot many api requests in a second  
then I  
am getting following errors randomly for some of the api requests:

1. TypeError (NilClass can’t be coerced into Float)
2. RuntimeError (can’t add a new key into hash during iteration)
3. Rendering /appl/mml/tomcat/server/mml-api1/webapps/api/500.html  
(500  
Internal Server Error)
4. Status: 500 Internal Server Error

Does newer jruby version solves this issue? But my application does not  
support jruby \> 1.7.3.

Also even if I add the affecting method in below synchronize block then  
also it is not synchronizing that method. Note : I have added  
“config.threadsafe!” in my development.rb & production.rb

semaphore = Mutex.new  
thread = Thread.new {  
semaphore.synchronize {  
#affecting code/method  
}  
}

But if I remove “config.threadsafe!” from my  
development.rb/production.rb &  
hit huge number of requests I am not getting any error but this time  
performance is impacted.

Is there any solution to remove these errors without affecting the  
performance?
