You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running json.dump concurrently across multiple threads can cause an ArrayIndexOutOfBoundsException:
warning: thread "Ruby-0-Thread-53: jrjack.rb:1" terminated with exception (report_on_exception is true):
java.lang.ArrayIndexOutOfBoundsException: 965
at sun.util.calendar.BaseCalendar.getCalendarDateFromFixedDate(BaseCalendar.java:453)
at java.util.GregorianCalendar.computeFields(GregorianCalendar.java:2397)
at java.util.GregorianCalendar.computeFields(GregorianCalendar.java:2312)
at java.util.Calendar.setTimeInMillis(Calendar.java:1804)
at java.util.Calendar.setTime(Calendar.java:1770)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:943)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:936)
at java.text.DateFormat.format(DateFormat.java:345)
at com.jrjackson.RubyAnySerializer.serializeTime(RubyAnySerializer.java:244)
at com.jrjackson.RubyAnySerializer.serialize(RubyAnySerializer.java:196)
at com.jrjackson.RubyAnySerializer.serializeHash(RubyAnySerializer.java:226)
at com.jrjackson.RubyAnySerializer.serialize(RubyAnySerializer.java:162)
at com.jrjackson.JrJacksonBase.generate(JrJacksonBase.java:73)
Snipped of code that reproduces the issue (courtesy of @jsvd)
require 'jrjackson'
Thread.abort_on_exception = true
now = Time.now
# we need multi threading to trigger this issue
num_threads = 100
threads = num_threads.times.map do |i|
Thread.new do
# this is OK:
# loop { JrJackson::Json.dump(now) }
# but this causes exception:
loop { JrJackson::Json.dump("a" => now) }
end
end
threads.each(&:join)
The text was updated successfully, but these errors were encountered:
Fixes ArrayIndexOutOfBoundsException that can occur when serializing dates concurrently.
Also cache the value of "UTC" TimeZone locally to avoid contention to synchronized
`getTimeZone` method.
Fixesguyboertje#76, guyboertje#77
* Fix concurrency issues
Fixes ArrayIndexOutOfBoundsException that can occur when serializing dates concurrently.
Also cache the value of "UTC" TimeZone locally to avoid contention to synchronized
`getTimeZone` method.
Fixes#76, #77
* Use a ThreadLocal to hold SimpleDateFormat
Avoid unnecessary (and expensive) SimpleDateFormat object creation
by storing in a ThreadLocal.
* Improve changelog message
* Fix typo in variable name
Running
json.dump
concurrently across multiple threads can cause anArrayIndexOutOfBoundsException
:Snipped of code that reproduces the issue (courtesy of @jsvd)
The text was updated successfully, but these errors were encountered: