> On Mar 9, 2016, at 9:55 AM, Emmanuel Lécharny <[email protected]> wrote:
> 
> The real question is : do we have to protect #7 at all ? graph is not a
> global variable, so there is no concurrent access issue here. Worse case
> scenario : two threads call loadGraph() with the same ContextID, but
> here, that mean we should check the conncury in loadgraph, not in
> getGraph().

So let’s dissect that function:

    private static SimpleDirectedGraph<String, Relationship> loadGraph( String 
contextId )
    {
        Hier inHier = new Hier( Hier.Type.ROLE );
        inHier.setContextId( contextId );
        LOG.info( "loadGraph initializing ROLE context [{}]", 
inHier.getContextId() );
        List<Graphable> descendants = null;
        try
        {
1           descendants = roleP.getAllDescendants( inHier.getContextId() );
        }
        catch ( SecurityException se )
        {
            LOG.info( "loadGraph caught SecurityException={}", se );
        }
2      Hier hier = HierUtil.loadHier( contextId, descendants );
        SimpleDirectedGraph<String, Relationship> graph;
3      graph = HierUtil.buildGraph( hier );
4      roleCache.put( getKey( contextId ), graph );
        return graph;
    }

The entire method needs to be synchronized as 1 - 4 need to be performed as a 
unit of work.

> 
> On Mar 9, 2016, at 9:55 AM, Emmanuel Lécharny <[email protected]> wrote:
> 
> 
> That of course assume roleCache itself to be thread-safe.

Yes

Reply via email to