Hi kernal team, When multiple threads access updatePermissionTree() method for the first time, they all will end up in the else block. Those threads will call the updatePermissionTreeFromDB() method one by one. Seems like this is creating a bottleneck in the execution flow.
void updatePermissionTree() throws UserStoreException { PermissionTreeCacheKey cacheKey = new PermissionTreeCacheKey(cacheIdentifier, tenantId); GhostResource<TreeNode> cacheEntry = (GhostResource<TreeNode>) permissionCache.get(cacheKey); if (permissionCache.containsKey(cacheKey)) { if (cacheEntry.getResource() == null) { synchronized (this) { cacheEntry = (GhostResource<TreeNode>) permissionCache.get(cacheKey); if (cacheEntry.getResource() == null) { updatePermissionTreeFromDB(); cacheEntry.setResource(root); if (log.isDebugEnabled()) { log.debug("Set resource to true"); } } } } } else { synchronized (this) { updatePermissionTreeFromDB(); cacheKey = new PermissionTreeCacheKey(cacheIdentifier, tenantId); cacheEntry = new GhostResource<TreeNode>(root); permissionCache.put(cacheKey, cacheEntry); if (log.isDebugEnabled()) { log.debug("Loaded from database"); } } } } Can this be modified as follows to avoid the above mentioned issue? void updatePermissionTree() throws UserStoreException { PermissionTreeCacheKey cacheKey = new PermissionTreeCacheKey(cacheIdentifier, tenantId); GhostResource<TreeNode> cacheEntry = (GhostResource<TreeNode>) permissionCache.get(cacheKey); if (cacheEntry != null && cacheEntry.getResource() != null) { return; } synchronized (this) { if (cacheEntry != null && cacheEntry.getResource() != null) { return; } if (cacheEntry == null) { cacheEntry = new GhostResource<TreeNode>(null); permissionCache.put(cacheKey, cacheEntry); } if (cacheEntry.getResource() == null) { updatePermissionTreeFromDB(); cacheEntry.setResource(root); if (log.isDebugEnabled()) { log.debug("Resource Loaded from database for cachekey: " + cacheEntry); } } } } Thanks, Chalitha -- *Chalitha Sanyuja Kulathunga* *Software Engineer* WSO2 Inc.; http://wso2.com email: chalit...@wso2.com cell: +94 77 5927581 <%2B94%2077%207779495>
_______________________________________________ Dev mailing list Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev