Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0037643Openbravo ERPA. Platformpublic2018-01-15 18:242018-02-22 18:18
AugustoMauch 
AugustoMauch 
normalminorhave not tried
closedfixed 
5
 
3.0PR18Q2 
caristu
Core
No
0037643: Improve the use of the ScriptEngine by reusing engine instance
Currently, each time that we want to eval a javascript expression using the ScriptEngine, we are create a new ScriptEngineManager and a new ScriptEngine instance. Then the bindings are set to the instance, and the expression is evaluated.

This can be improved by sharing a single instance of the Script, since creating the ScriptEngine can sometimes be expensive, and the class is thread safe (see [1])

[1] https://stackoverflow.com/a/30159424 [^]
-
Instead of creating a new ScriptEngine instance each time a javascript expression needs to be evaluated, reuse the same one and set the bindings to each evaluation, instead of to the engine itself.
Performance
Issue History
2018-01-15 18:24AugustoMauchNew Issue
2018-01-15 18:24AugustoMauchAssigned To => AugustoMauch
2018-01-15 18:24AugustoMauchModules => Core
2018-01-15 18:24AugustoMauchTriggers an Emergency Pack => No
2018-01-16 17:17hgbotCheckin
2018-01-16 17:17hgbotNote Added: 0101727
2018-01-16 17:17hgbotStatusnew => resolved
2018-01-16 17:17hgbotResolutionopen => fixed
2018-01-16 17:17hgbotFixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/120a6a75f9b757f20a7434d5cbb9d0cfe271a831 [^]
2018-01-16 18:16caristuReview Assigned To => caristu
2018-01-19 07:59alostaleTag Attached: Performance
2018-01-19 14:33hgbotCheckin
2018-01-19 14:33hgbotNote Added: 0101796
2018-01-19 14:34caristuNote Added: 0101797
2018-01-19 14:34caristuStatusresolved => closed
2018-01-19 14:34caristuFixed in Version => 3.0PR18Q1
2018-01-22 11:17caristuFixed in Version3.0PR18Q1 => 3.0PR18Q2
2018-02-22 18:18hudsonbotCheckin
2018-02-22 18:18hudsonbotNote Added: 0102659
2018-02-22 18:18hudsonbotCheckin
2018-02-22 18:18hudsonbotNote Added: 0102667

Notes
(0101727)
hgbot   
2018-01-16 17:17   
Repository: erp/devel/pi
Changeset: 120a6a75f9b757f20a7434d5cbb9d0cfe271a831
Author: Augusto Mauch <augusto.mauch <at> openbravo.com>
Date: Tue Jan 16 17:16:51 2018 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/120a6a75f9b757f20a7434d5cbb9d0cfe271a831 [^]

Fixes issue 37643: OBScriptEngine can be used to evaluate javascript scripts

There were four classes that were creating a new instance of ScriptEngine each time they needed to evaluate a javascript script. This was not the better way
to do it, since creating a ScriptEngine instance can be expensive, and that class is thread safety if properly used (i.e. by setting the bindings to each
evaluation instead of to the script engine itself).

A new singleton class has been added, OBScriptEngine, that is now used by all the classes that need to evaluate javascript scripts.

---
M modules/org.openbravo.client.application/src/org/openbravo/client/application/ParameterUtils.java
M modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewFieldHandler.java
M modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorDefaultFilterActionHandler.java
M src/org/openbravo/base/expression/Evaluator.java
A src/org/openbravo/base/expression/OBScriptEngine.java
---
(0101796)
hgbot   
2018-01-19 14:33   
Repository: erp/devel/pi
Changeset: 8dbb68df297c6ae5ad18149c9389ff399252b422
Author: Carlos Aristu <carlos.aristu <at> openbravo.com>
Date: Fri Jan 19 14:15:15 2018 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/8dbb68df297c6ae5ad18149c9389ff399252b422 [^]

related to issue 37643: avoid definining getInstance() method as synchronized

  The instance variable is now initialized on first class load instead.

---
M src/org/openbravo/base/expression/OBScriptEngine.java
---
(0101797)
caristu   
2018-01-19 14:34   
Code reviewed + tested OK.
(0102659)
hudsonbot   
2018-02-22 18:18   
A changeset related to this issue has been promoted main and to the
Central Repository, after passing a series of tests.

Promotion changeset: https://code.openbravo.com/erp/devel/main/rev/980a6ad5bbf5 [^]
Maturity status: Test
(0102667)
hudsonbot   
2018-02-22 18:18   
A changeset related to this issue has been promoted main and to the
Central Repository, after passing a series of tests.

Promotion changeset: https://code.openbravo.com/erp/devel/main/rev/980a6ad5bbf5 [^]
Maturity status: Test