Expand my Community achievements bar.

Mark Solution

This conversation has been locked due to inactivity. Please create a new post.

SOLVED

Admin resolver issue - Code doesn't execute completely

Avatar

Level 4

Hi,

I am using CQ5.6. I am using admin resolver to get session. I create nodes and then save the session using session.save(). I am creating multiple nodes in a loop. However each time when I run the code, I get session exception and code execution stops without creating all the nodes. Is it because of this admin resolver that my execution stops in between? What can be the solution?

16.09.2016 08:25:13.323 *WARN* [Finalizer] org.apache.jackrabbit.core.session.SessionState Attempt to close session-admin-1660298 while another thread is concurrently accessing this session. Blocking until the other thread is finished using this session. Please review your code to avoid concurrent use of a session. java.lang.Exception: Stack trace of concurrent access to session-admin-1660298
    at org.apache.jackrabbit.core.session.SessionState.close(SessionState.java:263)
    at org.apache.jackrabbit.core.SessionImpl.logout(SessionImpl.java:943)
    at org.apache.jackrabbit.core.XASessionImpl.logout(XASessionImpl.java:392)
    at com.day.crx.core.CRXSessionImpl.logout(CRXSessionImpl.java:127)
    at org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProvider.close(JcrResourceProvider.java:226)
    at org.apache.sling.resourceresolver.impl.helper.ResourceResolverContext.close(ResourceResolverContext.java:120)
    at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.close(ResourceResolverImpl.java:146)
    at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.finalize(ResourceResolverImpl.java:157)

 

Regards,

Shallu Rohilla

1 Accepted Solution

Avatar

Correct answer by
Employee

Make sure you close() the session in a finally{} block, I don't see the close in your code.

View solution in original post

4 Replies

Avatar

Employee Advisor

Hi,

looks like you are using a session with multiple threads. Don't do this, as it will cause all kind of weird problems.

Jörg

Avatar

Level 10

Please post the code so communuty can see what is happening.  Also, are you using Sling Mapping service to map system user to get a session?

Avatar

Level 4

Hi,

 

PFB code snippet:

ResourceResolver adminResolver = resolverFactory.getAdministrativeResourceResolver(null);

 

Session session = adminResolver.adaptTo(Session.class)

Node node= JcrUtils.getOrCreateByPath(livePath, DamConstants.NT_SLING_ORDEREDFOLDER, session);

for(Group group : groupDetail.getGroups()){
                        String nodeName = StringSimplifier.simplifiedString(group .getGroupName());
                        Node roleNode = dataScopesecurityRoleNode.addNode(dataNodeName );
                        roleNode .setProperty("dataRole", group.getGroupName());
                   
                        session.save();
                        
                        for(GroupIDs group1 : group.getGroupIDs()){
                     
                     
                            
                            Node childNode = roleNode .addNode(group1.getName(), "nt:unstructured");
     
                            
                            childNode.setProperty("role", group1.getGroupName());
                            childNode.setProperty("id", group1.getGroupID());
                            session.save();
                        }
                        
                    }
                    session.save();
                }

Avatar

Correct answer by
Employee

Make sure you close() the session in a finally{} block, I don't see the close in your code.