Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JRuby - The enterprise view

JRuby - The enterprise view

JRuby is often portrayed as the Ruby with brilliant Garbage Collection and native threads but poor startup time and large memory overhead. But how can JRuby really help you in a project, especially when you deal with large corporations that live in the Java world.

Leif Gensert

November 13, 2013
Tweet

More Decks by Leif Gensert

Other Decks in Programming

Transcript

  1. One of the best GCs in the world Native Threading

    Profiled Optimizations Native JIT True Parallelism (slow startup time)
  2. require 'java' ! java_import 'oracle.jdbc.OracleDriver' java_import 'java.sql.DriverManager' ! class OracleConnection

    ! def initialize (user, passwd, url) oradriver = OracleDriver.new ! DriverManager.registerDriver oradriver @conn = DriverManager.get_connection url, user, passwd end ! def create_statement() @conn.create_statement end ! def prepare_statement(sql) @conn.prepare_statement sql end ! def commit() @conn.commit end ! end The Oracle Way stmnt = conn.create_statement result_set = stmnt.execute_query 'select * from users' ! while result_set.next result_set.get_object('ID') end
  3. require 'java' ! java_import 'oracle.jdbc.OracleDriver' java_import 'java.sql.DriverManager' require 'sequel' !

    class OracleConnection def initialize (user, passwd, host, port, sid) url = "jdbc:oracle:thin:#{user}/#{passwd}@#{host}:#{port}:#{sid}" @client = Sequel.connect url end ! def query sql @client.fetch(sql) end end The Sequel Way client = OracleConnection.new('...') client.query('select * from users').each do |row| # { # id: 1, # first_name: 'Harry', # last_name: 'Hurtig', # user_name: 'hhurtig', # } end
  4. $ which java /usr/jdk/jdk1.6.0_51/bin/java ! $ wget http://jruby.org/.../jruby-bin-1.7.6.tar.gz $ tar

    zxf jruby-bin-1.7.6.tar.gz -C ~/jruby ! $ export PATH=~/jruby/bin:$PATH ! $ gem install bundler $ bundle install
  5. Conclusion • Not only GC and Native Threads • Take

    advantage of “Java is everywhere” • Embrace the JVM ecosystem
  6. Attribution • http://www.flickr.com/photos/tf28/4444660417 by TF28 ❘ tfaltings.de • http://www.flickr.com/photos/pedrosz/3993734789 by

    szeke • http://www.flickr.com/photos/nzdave/347532488 by (nz)dave • http://www.flickr.com/photos/cgranycome/9954708374 by CarolineG2011 • http://www.flickr.com/photos/digitalnc/8233509306 by North Carolina Digital Heritage Center • http://en.wikipedia.org/wiki/File:Java_virtual_machine_architecture.svg by Wikimedia Commons • http://www.flickr.com/photos/mdavidford/8650284288 by mdavidford • http://www.flickr.com/photos/apollo1981/1478327767 by apollo1981 • http://www.flickr.com/photos/yggg/287485592 by guccio@จ๪۩ࣾ • http://www.flickr.com/photos/kakutani/8281245690/ by kakutani • http://www.flickr.com/photos/barbro2009/5625148914 by Barbro_Uppsala