Skip to content

A subclass of Java's Timer object. VariableTimer allows for dynamic time intervals, defined by a function.

License

Notifications You must be signed in to change notification settings

mosca1337/VariableTimer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VariableTimer

A subclass of Java's Timer object. VariableTimer allows for dynamic time intervals, defined by a function. The value returned by the function is the period in milliseconds for each scheduled interval.

Usage

Here is an example of a Timer with a linear period. The period will start at one second and increase by one second every interval. This timer will execute after 1 second, 2 seconds, 3 seconds, … etc.

VariableTimer myTimer = new VariableTimer();
myTimer.scheduleAtVariableRate(new TimerTask() {
        public void run() {
            System.out.println("Executed!");
        }
    }, new Function() {
        public long function(long x) {
            return (1000 * x) + 1000;
        }
});

Here is an example of a Timer with an exponential period. This timer will execute immediately after 0 seconds, 1 second, 4 seconds, 9 seconds, … etc.

VariableTimer myTimer = new VariableTimer();
myTimer.scheduleAtVariableRate(new TimerTask() {
        public void run() {
            System.out.println("Executed!");
        }
    }, new Function() {
        public long function(long x) {
            return 1000 * x^2;
        }
});

Functions such as pause() and resume() are also supported.

License

This code is distributed under the terms and conditions of the MIT license.

About

A subclass of Java's Timer object. VariableTimer allows for dynamic time intervals, defined by a function.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages