Skip to content

Commit

Permalink
Translate java-api.en.md (#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyuguang committed Jul 18, 2020
1 parent c145dd3 commit 556a3a3
Showing 1 changed file with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,67 @@ weight = 2
chapter = true
+++

TODO
## Job configuration

ElasticJob-Lite uses the builder mode to create job configuration objects.
The code example is as follows:

```java
JobConfiguration jobConfig = JobConfiguration.newBuilder("myJob", 3).cron("0/5 * * * * ?").shardingItemParameters("0=Beijing,1=Shanghai,2=Guangzhou").build();
```

## Job start

ElasticJob-Lite scheduler is divided into two types: timed scheduling and one-time scheduling.
Each scheduler needs three parameters: registry configuration, job object (or job type), and job configuration when it starts.

### Timed scheduling

```java
public class JobDemo {

public static void main(String[] args) {
// Class-based Scheduling Jobs
new ScheduleJobBootstrap(createRegistryCenter(), new MyJob(), createJobConfiguration()).schedule();
// Type-based Scheduling Jobs
new ScheduleJobBootstrap(createRegistryCenter(), "MY_TYPE", createJobConfiguration()).schedule();
}

private static CoordinatorRegistryCenter createRegistryCenter() {
CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration("zk_host:2181", "elastic-job-demo"));
regCenter.init();
return regCenter;
}

private static JobConfiguration createJobConfiguration() {
// Create job configuration
...
}
}
```

### One-time scheduling

```java
public class JobDemo {

public static void main(String[] args) {
OneOffJobBootstrap jobBootstrap = new OneOffJobBootstrap(createRegistryCenter(), new MyJob(), createJobConfiguration());
// One-time scheduling can be called multiple times
jobBootstrap.execute();
jobBootstrap.execute();
jobBootstrap.execute();
}

private static CoordinatorRegistryCenter createRegistryCenter() {
CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration("zk_host:2181", "elastic-job-demo"));
regCenter.init();
return regCenter;
}

private static JobConfiguration createJobConfiguration() {
// Create job configuration
...
}
}
```

0 comments on commit 556a3a3

Please sign in to comment.