>
> Cheers,
>
> Patrick
>
> On Tue, May 31, 2011 at 2:43 PM, Patrick Bosek <
patrick.bosek <at> jorsek.com>
> wrote:
>>
>> Follow up question... Do I need to release or destroy the contexts I
>> create somehow?
>>
>> On Tue, May 31, 2011 at 2:34 PM, Patrick Bosek <
patrick.bosek <at> jorsek.com>
>> wrote:
>>>
>>> Hi everyone,
>>>
>>> I'm trying to figure out when I should and should not release a broker,
>>> as it seems to be critical to eXist running well.
>>>
>>> So, right now I'm getting these is my exist.log:
>>> 2011-05-31 13:21:32,314 [P1-8] ERROR (BrokerPool.java [release]:1312) -
>>> release() has been called from the wrong thread for broker null
>>>
>>> Which I assume is because I'm releasing a broker when I shouldn't. These
>>> are appearing most notably after creating a new broker and a new context,
>>> then releasing the broker. Like this:
>>>
>>> class myUtil {
>>>
>>> public static XQueryContext getNewContextAsUser(String username){
>>>
>>> NativeBroker broker = getBrokerAsUser(username);
>>>
>>> XQueryContext newContext = new XQueryContext(broker,
>>> AccessContext.XMLRPC);
>>>
>>> return newContext;
>>> }
>>>
>>> public static NativeBroker getBrokerAsUser(String username)
>>> {
>>> BrokerPool pool;
>>> NativeBroker broker = null;
>>> try {
>>> pool = BrokerPool.getInstance();
>>>
>>> org.exist.security.SecurityManager security =
>>> pool.getSecurityManager();
>>> User asUser = security.getUser(username);
>>>
>>> broker = new NativeBroker(pool, pool.getConfiguration());
>>>
>>> broker.setUser(asUser);
>>>
>>> } catch (EXistException e) {
>>> System.out.println("Exception in getBrokerAsUser: " + e);
>>> e.printStackTrace();
>>>
>>> return null;
>>> }
>>>
>>> return broker;
>>> }
>>>
>>> public static void brokerReleaseWrapper(DBBroker broker)
>>> {
>>> StackTraceElement[] trace = new Throwable().getStackTrace();
>>>
>>> existLOG.info("brokerReleaseWrapper being called");
>>> for(int i = 0; i < 4; i++)
>>> existLOG.info(trace[i]);
>>>
>>> broker.getBrokerPool().release(broker);
>>> }
>>>
>>> }
>>>
>>> // Code that's causing the error
>>>
>>> XQueryContext context =
>>> myUtil.getNewContextAsUser(org.exist.security.SecurityManager.DBA_USER);
>>>
>>> NativeBroker broker = (NativeBroker) context.getBroker();
>>>
>>> try{
>>>
>>> *** DO STUFF ****
>>> } finally{
>>> broker.setUser(currentUser);
>>> myUtil.brokerReleaseWrapper(broker);
>>> }
>>>
>>>
>>>
>>> In general, when do I need to be sure I release a broker?
>>>
>>>
>>> Does the XQueryContext release it's broker automatically somehow?
>>>
>>>
>>>
>>> Thanks!
>>>
>>>
>>> --
>>> Patrick Bosek
>>> Jorsek Software
>>> Cell (585) 820 9634
>>> Office (585) 239 6060
>>> Jorsek.com
>>>
>>
>>
>>
>> --
>> Patrick Bosek
>> Jorsek Software
>> Cell (585) 820 9634
>> Office (585) 239 6060
>> Jorsek.com
>>
>
>
>
> --
> Patrick Bosek
> Jorsek Software
> Cell (585) 820 9634
> Office (585) 239 6060
> Jorsek.com
>
>