title: Loading non-thread-safe native lib in Vert.x: are multi-instance verticles confined to their own process
body: <p>I would like to write a verticle that renders graphs using GraphViz. I would like to do it by loading the native (shared) libs into my JVM and calling it via JNI. Now, GraphViz itself is not thread-safe. It is not enough to run each of the multi-instance verticles always in their own thread, I must additionally ensure that each verticle gets its own instance of the native code, or in other words, that every verticle runs in a separate process, each utilizing one of the cores. </p>
  
  <p>Most descriptions of Vert.x say talk only about isolation between threads (not sharing data etc.) I have found nothing about process isolation. </p>
  
  <p>Basically I'm looking for a framework to create a couple of instances of a REST server, all listening on the same socket or with a loadbalancer in front, and not having to write any of the code myself. Sort of what PM2 does for Node.js. Can I do that with Vert.x?</p>
  
  <p>I realize this may be against the spirit of Vert.x, as the core documentation makes clear:</p>
  
  <blockquote>
    <p>Instead of a single event loop, each Vertx instance maintains several event loops. By default we choose the number based on the number of available cores on the machine, but this can be overridden.</p>
    
    <p>This means a single Vertx process can scale across your server, unlike Node.js.</p>
  </blockquote>
  
  <p>But as I am using native libraries, which can only be loaded once per JVM, and in my case cannot execute concurrently, and so prevent scaling out to multiple cores, I guess I really do want the Node.js pattern, only in Java.</p>
  
  <p>My requirement is also much simpler than what is described in the documentation of clustered event bus, e. g. the <a href="https://github.com/vert-x3/vertx-examples/tree/master/zookeeper-examples" rel="nofollow noreferrer">Zookeeper example</a>, because I need no communication between the instances.</p>