[
https://issues.apache.org/jira/browse/JEXL-194?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15282561#comment-15282561
]
Henri Biestro commented on JEXL-194:
------------------------------------
As a temporary workaround, you already can run code under a 'synchronized'
monitor as in :
{code}
public static class Synchronizer extends MapContext {
private final JexlContext context;
public Synchronizer(JexlContext ctxt) {
this.context = ctxt;
}
public Object call(Object var, JexlScript script) {
String[] parms = script.getParameters();
boolean varisarg = parms != null && parms.length == 1;
if (var == null) {
return varisarg? script.execute(context, var) :
script.execute(context);
} else {
synchronized (var) {
return varisarg? script.execute(context, var) :
script.execute(context);
}
}
}
}
@Test
public void test196() throws Exception {
Map<String, Object> ns = new TreeMap<String, Object>();
ns.put("synchronized", Synchronizer.class);
JexlContext jc = new MapContext();
JexlEngine jexl = new JexlBuilder().namespaces(ns).create();
JexlScript js0 = jexl.createScript("synchronized:call(x,
(y)->{y.size()})", "x");
Object size = js0.execute(jc, "foobar");
Assert.assertEquals(6, size);
}
{code}
> synchronize on iterableValue in foreach statement
> -------------------------------------------------
>
> Key: JEXL-194
> URL: https://issues.apache.org/jira/browse/JEXL-194
> Project: Commons JEXL
> Issue Type: Improvement
> Affects Versions: 3.0
> Reporter: Dmitri Blinov
> Assignee: Henri Biestro
> Priority: Minor
>
> Since it is a requirement to synchronize on simple Collections and
> synchronized Collections while iterating over them and since jexl has no
> instrument to control synchronization in script, I think its reasonable to
> implement synchronization in jexl itself on iterableValue. In case of
> concurrent collections it will possibly block other threads only if they are
> synchronizing on those collections themselves, which will be complementary to
> required synchronization in jexl.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)