Thread.current strangeness

In rails threaded mode, whether running under webrick or tomcat,
Thread.current.object_id is different for every request. I assumed
that this would be unique per thread but it doesn’t appear that’s the
case. Can someone explain what’s going on?

Chris

Hi,

On Wed, May 25, 2011 at 08:12, snacktime [email protected] wrote:

In rails threaded mode, whether running under webrick or tomcat,
Thread.current.object_id is different for every request. I assumed
that this would be unique per thread but it doesn’t appear that’s the
case. Can someone explain what’s going on?

jruby-rack/tomcat implements thread pool so a single thread handles
multiple requests. Plus, object_id can be reused in CRuby so it’s not
unique.

% ruby -e ‘5.times { p Object.new.object_id; GC.start }’
8821320
8822500
7550420
7550420
7550420

You would see unique object_id values in JRuby but you should not
depend its uniqueness.

Regards,
// NaHi