Peter K Chan wrote:
I am wondering if there is any potential problem with running a Ruby block
in a different native java.lang.Thread?

My code converts a block into a java.lang.Runnable and starts it directly
using the Java thread constructor. I am not using RubyThread, because I need
to start a daemon thread.

I am seeing some sporadic NPE in my code. About one-third of the time, when
starting a block in a different (native) Java thread, I see error below (1.0
RC3 revision 3714):

Exception in thread "NET2" java.lang.NullPointerException
        at org.jruby.runtime.Block.call(Block.java:174)
        at org.jruby.RubyProc.call(RubyProc.java:173)
        at org.jruby.RubyProc.call(RubyProc.java:148)
        at org.jruby.javasupport.Java$1.invoke(Java.java:853)
        at $Proxy0.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:595)

Any tip on this would be greatly appreciated.

Hmm...well to start, blocks are not generally supposed to be called across threads, but procs can be. Procs/lambdas handle the local scoping and framing a bit differently so that multiple callers don't interfere with each other. I would recommend that if you're going to memoize the block and call it across threads, that you first turn it into a proc or lambda.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to