Run a java function after a specific number of seconds

new java.util.Timer().schedule( 
        new java.util.TimerTask() {
            public void run() {
                // your code here


javadoc says:

After the last live reference to a Timer object goes away and all outstanding tasks have completed execution, the timer’s task execution thread terminates gracefully (and becomes subject to garbage collection). However, this can take arbitrarily long to occur.

Leave a Comment