Is it possible to restrict the amount of time the user code runs in JRuby?
+1
A:
Not sure how you're embedding the Ruby code, but you could easily have a background timer thread that evaluates
raise YourTimeLimitExceededException, 'no more time'
after a period of time. You'd also want to disable Thread.new and Thread.start (as well as java.lang.Thread.new) for the user code, or they could easily circumvent your timer.
Nick Sieger
2010-08-02 18:04:26
Can you elaborate on your answer, please? (I'm using JRuby-embed)
instantsetsuna
2010-08-16 04:46:42
Have a background thread measure the time spent, and call `scriptingContainer.evalScriptlet("raise Timeout::Timeout")` from the timer thread. You could use java.util.concurrent futures to help with making sure that the timeout doesn't get raised if the script completes in time.
Nick Sieger
2010-08-16 20:54:11
Thanks for the answer, I'll look into it! :)
instantsetsuna
2010-08-18 04:54:57