Created
November 16, 2009 12:33
-
-
Save chrisa/235955 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.venda.jruby; | |
| import java.util.ArrayList; | |
| import org.jruby.Ruby; | |
| import org.jruby.RubyObjectAdapter; | |
| import org.jruby.RubyRuntimeAdapter; | |
| import org.jruby.javasupport.JavaEmbedUtils; | |
| import org.jruby.runtime.builtin.IRubyObject; | |
| import org.jruby.RubyInstanceConfig; | |
| public class Harness { | |
| private RubyRuntimeAdapter rubyRuntimeAdapter = JavaEmbedUtils.newRuntimeAdapter(); | |
| private RubyObjectAdapter rubyObjectAdapter = JavaEmbedUtils.newObjectAdapter(); | |
| public static void main(String[] args) throws InterruptedException { | |
| Harness h = new Harness(); | |
| h.go(); | |
| Thread.sleep(1000000); | |
| } | |
| Harness() { | |
| } | |
| public void go() throws InterruptedException { | |
| ArrayList<LikeMessageThread> threads = new ArrayList<LikeMessageThread>(); | |
| RubyInstanceConfig config = new RubyInstanceConfig(); | |
| Ruby runtime = JavaEmbedUtils.initialize(new ArrayList(), config); | |
| for (int i = 0; i < 25000; i++) { | |
| LikeMessageThread t = new LikeMessageThread(runtime); | |
| threads.add(t); | |
| } | |
| for (LikeMessageThread t : threads) { | |
| t.start(); | |
| } | |
| for (LikeMessageThread t : threads) { | |
| t.join(); | |
| } | |
| } | |
| private class LikeMessageThread extends Thread { | |
| private Ruby runtime; | |
| LikeMessageThread(Ruby runtime) { | |
| this.runtime = runtime; | |
| } | |
| @Override | |
| public synchronized void run() { | |
| try { | |
| IRubyObject obj = rubyRuntimeAdapter.eval(runtime, "Kernel"); | |
| rubyObjectAdapter.callMethod(obj, "p", new IRubyObject[] { | |
| JavaEmbedUtils.javaToRuby(runtime, this.toString())}); | |
| } catch (Exception e) { | |
| System.out.println("exception: " + e.getMessage()); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment