Since it is volatile you could remove the synchronized on
getGraphDatabase() but if your app depends on getting null graphdb
when context has been destroyed you would have to rewrite the
contextDestroyed to something like:

    public void contextDestroyed( ServletContextEvent event )
    {
        synchronized ( GraphDatabaseContext.class )
        {
            GraphDatabaseService neo = graphDb;
            graphDb = null;
            if ( neo != null ) neo.shutdown();
        }
    }

What we really want is final but not possible to do here.

-Johan

On Tue, Jun 7, 2011 at 10:12 AM, McKinley <mckinley1...@gmail.com> wrote:
> Johan,
>
> In that Servlet example is the synchronized get on the graphDb reference
> still necessary on the ServletContextListener?
>
> Thanks,
>
> McKinley
>
> On Tue, Jun 7, 2011 at 1:03 AM, Johan Svensson <jo...@neotechnology.com>wrote:
>
>> Hi,
>>
>> You can assume all Neo4j APIs are thread safe. If something is not
>> thread safe it will be explicitly stated in the javadocs.
>>
>> If you keep all state that has to be shared between threads in the
>> graph and all other state thread local you don't have to perform any
>> external (or extra) synchronization at all. If you have state that is
>> not graph data and needs to be shared between threads keep that in
>> separate synchronization blocks without invoking any mutating
>> operations on the graph.
>>
>> Regards,
>> Johan
>>
>> On Sat, Jun 4, 2011 at 7:22 PM, McKinley <mckinley1...@gmail.com> wrote:
>> > I'm working with Neo4j as an EmbeddedGraphDatabase on a web server. It is
>> > not Servlets, but the same multi threaded concerns apply. Is this
>> > http://wiki.neo4j.org/content/Servlets_with_Neo4j still the most current
>> > example of dealing with multi threaded concerns?
>> >
>> > I see many mentions on avoiding unnecessary uses of synchronized in the
>> > current documentation at http://docs.neo4j.org/. Can those warnings in
>> the
>> > documentation have a simple multi threaded example included too?
>> >
>> > Thanks,
>> >
>> > McKinley
_______________________________________________
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to