Created
September 14, 2015 11:29
-
-
Save lundvall/8b2fd24dbcc68415a397 to your computer and use it in GitHub Desktop.
Ratpack scheduled service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ratpack.exec.ExecController; | |
import ratpack.server.Service; | |
import ratpack.server.StartEvent; | |
import ratpack.server.StopEvent; | |
import java.util.concurrent.TimeUnit; | |
public class ScheduledService implements Service, Runnable { | |
public String getName() { | |
return getClass().getSimpleName(); | |
} | |
public void onStart(StartEvent event) throws Exception { | |
ExecController.require().getExecutor() | |
.scheduleAtFixedRate(this, 0, 5, TimeUnit.SECONDS); | |
} | |
public void onStop(StopEvent event) throws Exception { | |
System.out.println("stop:" + getName()); | |
} | |
public void run() { | |
ExecController.require().fork().start(e -> { | |
System.out.println("running: " + getName()); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment