killme2008 / aviatorscript

A high performance scripting language hosted on the JVM.
http://fnil.net/aviator/
4.46k stars 831 forks source link

How to make functions local in multi-threading environment #53

Closed hsluoyz closed 6 years ago

hsluoyz commented 6 years ago

I want to use aviator in a multi-threading environment. Each thread uses aviator to evaluate expressions. But the AviatorEvaluator.addFunction() is a static method. So it is global and will influence all threads. But I only want each thread to specify its own functions. Can you make addFunction() a local method, like an instance method?

hsluoyz commented 6 years ago

BTW, I'm using this library in: https://github.com/casbin/jcasbin, an access control library for Java

killme2008 commented 6 years ago

@hsluoyz Yep, the aviator evaluator is a global instance,it's not a good practice for some usages.I think it's a good idea to provide evaluator instances for different usages.

killme2008 commented 6 years ago

4.0.0-RC released, and it supports multi AviatorEvaluatorInstance. You can create a instance by:

AviatorEvaluatorInstance instance = AviatorEvaluator.newInstance();
instance.exec(......)

And every instance has it's own options,custom functions and operators.

https://github.com/killme2008/aviator/releases/tag/aviator-4.0.0-RC