It doesn't hang for me, you only create open transactions in your code that 
you never close, so Neo4j's shutdown method waits for 20 seconds for these 
transactions to finish, until it finally forces the db to shut down.

Here is your fixed code, the pattern _MUST_ be:

try(Transaction t = db.beginTx()) {

  t.success();
}

The "MappedByteBuffer" param makes no difference, you just messed up the 
transaction usage pattern.

This code runs in a few ms.

import org.neo4j.graphdb.*;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;

import java.io.File;
import java.io.IOException;

class Main {
    private Node root;
    private GraphDatabaseService graph;
    public static final Label TEST = DynamicLabel.label("test");

    private static enum Relationships implements RelationshipType {CONTAINS}

    Main() throws IOException {
        try {
            File location = setupLocation();
            graph = new 
GraphDatabaseFactory().newEmbeddedDatabase(location.getPath());
            try (Transaction t = graph.beginTx()) {
                root = graph.createNode();
                t.success();
            }
        } catch (Exception e) {
            if (graph != null)
                graph.shutdown();
            throw new IOException("Could NOT start storage");
        }
    }

    private File setupLocation() {
        File location = new File("location");
        if (location.isFile())
            location.renameTo(new File(location.getName() + '.' + 
System.currentTimeMillis()));
        if (!location.exists())
            location.mkdirs();
        return location;
    }

    public void shutDown() {
        graph.shutdown();
    }

    public void hang() {
        try (Transaction t = graph.beginTx()) {
            if (!root.hasLabel(TEST)) {
                Node gn = graph.createNode();
                root.createRelationshipTo(gn, Relationships.CONTAINS);
            }
            t.success();
        }
    }

    public static void main(String[] args) {
        try {
            Main m = new Main();
            m.hang();
            m.shutDown();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to