常规监听器

  1. public class JobMain {
  2. public static void main(String[] args) {
  3. new ScheduleJobBootstrap(createRegistryCenter(), createJobConfiguration()).schedule();
  4. }
  5. private static CoordinatorRegistryCenter createRegistryCenter() {
  6. CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration("zk_host:2181", "elastic-job-demo"));
  7. regCenter.init();
  8. return regCenter;
  9. }
  10. private static JobConfiguration createJobConfiguration() {
  11. JobConfiguration jobConfiguration = JobConfiguration.newBuilder("test", 2)
  12. .jobListenerTypes("simpleListener", "distributeListener").build();
  13. }
  14. }

分布式监听器

  1. public class JobMain {
  2. public static void main(String[] args) {
  3. new ScheduleJobBootstrap(createRegistryCenter(), createJobConfiguration()).schedule();
  4. }
  5. private static CoordinatorRegistryCenter createRegistryCenter() {
  6. CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration("zk_host:2181", "elastic-job-demo"));
  7. regCenter.init();
  8. return regCenter;
  9. }
  10. private static JobConfiguration createJobConfiguration() {
  11. JobConfiguration jobConfiguration = JobConfiguration.newBuilder("test", 2)
  12. .jobListenerTypes("simpleListener", "distributeListener").build();
  13. }
  14. }