Source:
<code>static void shutdownGraphDatabaseService(GraphDatabaseService neo4jDb) { GraphDatabaseAPI sq = (GraphDatabaseAPI) neo4jDb; String key = sq.getStoreDir().getAbsolutePath(); if ( GRAPH_DATABASE_SERVICE_MAP.containsKey( key ) ) { <START> synchronized (GRAPH_DATABASE_SERVICE_MAP) { <END> FactoryHolder factoryHolder = GRAPH_DATABASE_SERVICE_MAP.get( key ); factoryHolder.setCounter( factoryHolder.getCounter() - 1 ); LOG.debugf( " Counter : %s for path %s", factoryHolder.getCounter(), key ); GraphDatabaseFacade graphDatabaseFacade = factoryHolder.getGraphDatabaseFacade(); try { GraphDatabaseFacade.SPI spi = null; Object obj = getPrivateField( GraphDatabaseFacade.class.getDeclaredField( "spi" ), graphDatabaseFacade ); spi = (GraphDatabaseFacade.SPI) obj; LOG.debugf( " isInOpenTransaction: %s", spi.isInOpenTransaction() ); if ( spi.isInOpenTransaction() ) { LOG.warnf( "currentTransaction %s started at %s", spi.currentTransaction() , spi.currentTransaction().startTime() ); spi.currentTransaction().failure(); spi.currentTransaction().closeTransaction(); throw LOG.existsOpenTransactionsFornDatabasePathException( key ); } } catch ( IllegalAccessException | NoSuchFieldException e) { throw new HibernateException( "Can't get value of private variable by reflection!",e ); } catch (TransactionFailureException e) { throw new HibernateException( "Can't close transction!",e ); } if ( factoryHolder.getCounter() == 0 ) { LOG.infof( " Shutdown db for path : %s", key ); factoryHolder.getGraphDatabaseFacade().shutdown(); GRAPH_DATABASE_SERVICE_MAP.remove( key ); } } } else { throw LOG.unknownDatabasePathException( key ); } }</code><technical_language>need a nested synchronized</technical_language>

Target:
static void shutdownGraphDatabaseService(GraphDatabaseService neo4jDb) { GraphDatabaseAPI sq = (GraphDatabaseAPI) neo4jDb; String key = sq.getStoreDir().getAbsolutePath(); if ( GRAPH_DATABASE_SERVICE_MAP.containsKey( key ) ) { final FactoryHolder factoryHolder = GRAPH_DATABASE_SERVICE_MAP.get( key ); synchronized (factoryHolder) { factoryHolder.setCounter( factoryHolder.getCounter() - 1 ); LOG.debugf( " Counter : %s for path %s", factoryHolder.getCounter(), key ); GraphDatabaseFacade graphDatabaseFacade = factoryHolder.getGraphDatabaseFacade(); try { GraphDatabaseFacade.SPI spi = null; Object obj = getPrivateField( GraphDatabaseFacade.class.getDeclaredField( "spi" ), graphDatabaseFacade ); spi = (GraphDatabaseFacade.SPI) obj; LOG.debugf( " isInOpenTransaction: %s", spi.isInOpenTransaction() ); if ( spi.isInOpenTransaction() ) { LOG.warnf( "currentTransaction %s started at %s", spi.currentTransaction(), spi.currentTransaction().startTime() ); spi.currentTransaction().failure(); spi.currentTransaction().closeTransaction(); throw LOG.existsOpenTransactionsFornDatabasePathException( key ); } } catch (IllegalAccessException | NoSuchFieldException e) { throw new HibernateException( "Can't get value of private variable by reflection!", e ); } catch (TransactionFailureException e) { throw new HibernateException( "Can't close transction!", e ); } if ( factoryHolder.getCounter() == 0 ) { LOG.infof( " Shutdown db for path : %s", key ); factoryHolder.getGraphDatabaseFacade().shutdown(); GRAPH_DATABASE_SERVICE_MAP.remove( key ); } } } else { throw LOG.unknownDatabasePathException( key ); } }