Hi everybody,
when working with scheduled commands we often receive this exception:
[b]org.apache.jackrabbit.core.SessionImpl: Unclosed session detected[/b]
the reason is well explained here [1] and here [2], but I would like to know
how to avoid it while trying to use JCR with Threads that are not initialized
by a request.
Looking in Magnolia source code, I've found this:
class: info.magnolia.module.observation.commands.CommandEventListener
method: onEvent
[code]
// initialize context
Context ctx;
if (MgnlContext.hasInstance()) {
ctx = MgnlContext.getInstance();
} else {
ctx = new SimpleContext(MgnlContext.getSystemContext()) {
public void release() {
// release is done on system context
}
};
}
MgnlContext.setInstance(ctx);
[/code]
So I have adapted in this way:
[code]
public Context getSafeContext() {
return getSafeContext(true);
}
public Context getSafeContext(final boolean setForThisThread) {
Context ctx;
if (MgnlContext.hasInstance()) {
ctx = MgnlContext.getInstance();
} else {
ctx = new SimpleContext(MgnlContext.getSystemContext()) {
@Override
public void release() {
// release is done on system context
}
};
}
if (setForThisThread) {
MgnlContext.setInstance(ctx);
}
return ctx;
}
[/code]
But when I try to access 2 different repositories within the same Thread
execution, I receive anyway the exception above.
Can you point me on the right direction to solve this issue?
Thanks a lot
Matteo
----
[1]:
http://jackrabbit.510166.n4.nabble.com/WARN-Unclosed-session-detected-td522225.html
[2]:
http://forum.magnolia-cms.com/forum/thread.html?threadId=bd9a84fe-57ab-428a-bf97-30c18b77a36a#7fdd3124-b11d-4043-b00c-22dbafb2f28a
--
Context is everything:
http://forum.magnolia-cms.com/forum/thread.html?threadId=0581bc5d-23cd-49af-b8f6-8c34b8ad42b2
----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------