@Test
    public void shouldBeAbleToReUseBuilderInDifferentThreads() throws Exception {
        final ByteArrayOutputStream os = new ByteArrayOutputStream();
        final GraphWriter writer = GryoWriter.build().create();
        writer.writeVertex(os, new DetachedVertex(1, "test", new HashMap<>()));
        os.close();

        final byte[] bytes = os.toByteArray();

        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicBoolean assertProcess1 = new AtomicBoolean(false);
        final AtomicBoolean assertProcess2 = new AtomicBoolean(false);
        final AtomicBoolean assertProcess3 = new AtomicBoolean(false);

        // just one builder to re-use among threads
        final GryoReader.Builder builder = GryoReader.build();

        final Thread process1 = new Thread(() -> {
            try {
                latch.await();
                final GryoReader reader = builder.create();
                final Vertex v = reader.readVertex(new ByteArrayInputStream(bytes), Attachable::get);
                assertProcess1.set(v.id().equals(1));
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        });

        final Thread process2 = new Thread(() -> {
            try {
                latch.await();
                final GryoReader reader = builder.create();
                final Vertex v = reader.readVertex(new ByteArrayInputStream(bytes), Attachable::get);
                assertProcess2.set(v.id().equals(1));
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        });

        final Thread process3 = new Thread(() -> {
            try {
                latch.await();
                final GryoReader reader = builder.create();
                final Vertex v = reader.readVertex(new ByteArrayInputStream(bytes), Attachable::get);
                assertProcess3.set(v.id().equals(1));
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        });

        process1.start();
        process2.start();
        process3.start();

        latch.countDown();

        process3.join();
        process2.join();
        process1.join();

        assertTrue(assertProcess1.get());
        assertTrue(assertProcess2.get());
        assertTrue(assertProcess3.get());
    }
@author Stephen Mallette (http://stephen.genoprime.com)
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoReaderWriterTest.java