You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bsf-user@jakarta.apache.org by Sanka Samaranayake <sa...@opensource.lk> on 2004/07/05 07:53:58 UTC

Re: BSF and thread safety

Hi,

(1)Do I need to maintain a separate BSFManager and a BSFEngine per thread?
I think so ..
since your evaluations require declaration of the variables independently
you need separate BSFManager objects and load the scripting engines from
them separately for the evaluations. Otherwise if one thread declare a
variable it will be available it the next thread right after. Pls note
that none of the methods in BSFManager nor the BSFEngine are synchronized.


(2) Are BSFManager and BSFEngine reusable?
Yes they are ..
Pls note that BSFManager loads a scripting engine only once and reuses it
then onwards. Therefore if you use the same BSFManager object (and loads
the scripting engine form it) for different evaluations the scripting
engines are reused automatically. But if you want to get rid of the
declared variables you should call undeclareBean(…) before the next
evaluation.

Cheers !!

Sanka Samaranayake


> Hi.
>
> I'm developing a solution for web application controller and plan to use
> BSF as expression evaluation engine.
> What I need is to evaluate expressions in contexts of various variables
> extracted from the client's request. These evaluations must be
> completely independent. Moreover, there will be plenty of evaluations
> carried out by various threads in parallel. I have a couple of
> questions, would appreciate your answers.
>
> Each evaluation is handled in the context of declared variables.
> Variables are declared using manager.declareBean(...). Do I need a
> separate BSFManager and BSFEngine per thread? Or is there a way to have
> one BSFManager and produce only a BSFEngine per thread (with respect to
> variables, which must not be shared between threads)?
>
> Are BSFManager and BSFEngine reusable? Can I pool BSFManager and
> BSFEngine and reuse them for different evaluations (cleaning up the
> variable, of course)?
>
> Thanks for your answers.
>
> Bye.
> /lexi
>
> --
> Dr. Aleksei Valikov (RUS)
> Wissenschaftlicher Mitarbeiter
> Forschungszentrum Informatik
>
> Haid-und-Neu Str. 10-14
> 76131 Karlsruhe, Deutschland
>
> Tel: +49-721-9654716
> Fax: +49-721-9654717
> E-mail: valikov@fzi.de
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bsf-user-help@jakarta.apache.org
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org


Re: BSF and thread safety

Posted by Aleksei Valikov <va...@gmx.net>.
Hi.

> (1)Do I need to maintain a separate BSFManager and a BSFEngine per thread?
> I think so ..
> since your evaluations require declaration of the variables independently
> you need separate BSFManager objects and load the scripting engines from
> them separately for the evaluations. Otherwise if one thread declare a
> variable it will be available it the next thread right after. Pls note
> that none of the methods in BSFManager nor the BSFEngine are synchronized.
> 
> (2) Are BSFManager and BSFEngine reusable?
> Yes they are ..
> Pls note that BSFManager loads a scripting engine only once and reuses it
> then onwards. Therefore if you use the same BSFManager object (and loads
> the scripting engine form it) for different evaluations the scripting
> engines are reused automatically. But if you want to get rid of the
> declared variables you should call undeclareBean(…) before the next
> evaluation.

Thanks.
Looks like a good solution will be a pool of BSFManagers. For every 
evaluation I'll retrieve a manager from the pool, load an engine from it 
and clear the variables afterwards.

Thanks again for the answers.

Bye.
/lexi

---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org