BeanShell provides to execute code snippets at runtime without compiling and restarting JVM. This functionality enables us to execute custom operations at runtime. Lets consider following case: Admin user of our system wants to manipulate a system value at runtime and enters a configuration for that purpose. Lets say, parameter, which manipulation will be executed on, holds a string tokenized with pipe character and we wants to change its value by finding max part of tokenized values.
Here is how that operation can be implemented with pure java
Now lets see if this operation shall be done at runtime with provided code snippet:
As easy as much above. Here is output:
Finally, i must say that altough first execution takes some time, succeeding executions takes faily short time. BeanShell provides us significant flexibility over processes at runtime.