Scheduled Execution

From Multiverse

Jump to: navigation, search

The class multiverse.server.engine.Engine provides a mechanism for scheduling tasks for execution at some future time. To schedule a task:

  1. Create a class (in Java or Python) that implements the Runnable interface.
  2. Call Engine.getExecutor().scheduleAtFixedRate() with the following arguments:
    • The class that implements Runnable.
    • Initial delay before execution.
    • Subsequent interval between executions.
    • Time unit (TimeUnit.NANOSECONDS, TimeUnit.MICROSECONDS, TimeUnit.MILLISECONDS, or TimeUnit.SECONDS)

This method returns a java.util.concurrent.ScheduledThreadPoolExecutor object, that you can use in a variety of ways to schedule execution.




Here is a Python example:

class PeriodicExample (Runnable):
  def run(self):
    WorldManagerClient.sendSysChatMsg("periodic example")

The line below runs this periodic example, initially 30 seconds after execution of the statement, then subsequently every 60 seconds:

Engine.getExecutor().scheduleAtFixedRate(PeriodicExample(), 30, 60, TimeUnit.SECONDS)
Personal tools