Java and Javascript Configuration with Functions

For the last few years I’ve been playing with a simple configuration system which I call ‘runtime properties’.

Runtime properties are similar to Java system properties in concept but differ in a few ways.

They’re designed to replace variables during VM initialization with values in a given property file. When you reference a named Java static and non-final variable it will change the value in your VM reflecting the value in the property file.

For example.

Let’s say we had a class named org.feedblog.Main with a static and non-final variable of NUM_THREADS.

Let’s say this had the default value of 1 but we want to change it to 10 to increase the throughput of some algorithm.

In your file you would enter:


Now when you restart your VM it will reflect the value of 10 and store the updated value in your VM before any additional code is called.

It’s designed to be a simple unix-like configuration system for the inherently non-Unix Java runtime.

It supports a number of other features like type detection, include support, document literals, etc.

A feature that I’ve been thinking about for a while is the ability to include a function in Java source code and have that function called in Java at runtime.

If you would default a value such as:

import org.mozilla.javascript.Function;
public static Function RECRAWL_RATE_FUNC = null;

Then you could declare this in your file via:

# Take a given value as a function parameter (in milliseconds
# since epoch) and return an interval (in milliseconds) to 
# recrawl a post.

    var MULT=2;

    var f=function(update_interval) {

       if ( update_interval == null )
          return 2 * 60 * 60 * 1000;

       return update_interval = update_interval * MULT;



This would allow you to push selective code updates as configuration directives and wouldn’t require entire code pushes to the whole cluster.

During initialization the VM would simply throw an Exception if the code doesn’t eval() correctly.

There would be a few other risks involved with the code having a bug created by your configuration directive but this shouldn’t be more problematic than normal configuration directives.

%d bloggers like this: