A checkpoint is a class and method marker, and it is used when you want a piece of code, even if executed by several independent processes, to be executed only once.
If you need to know if a piece of code has already been executed by another process, then this is the perfect library for you. A checkpoint is a class and method marker, and it is used when you want a piece of code, even if executed by several independent processes, to be executed only once.
- Add one of the options below to the pom.xml file:
<dependency>
<groupId>io.github.wniemiec-task-java</groupId>
<artifactId>checkpoint</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>wniemiec.task.java</groupId>
<artifactId>checkpoint</artifactId>
<version>LATEST</version>
</dependency>
- Run
$ mvn install
- Use it
[...]
import wniemiec.task.java.Checkpoint;
[...]
public class CheckpointExample {
[...]
Checkpoint checkpoint = new Checkpoint(tmpDir, "checkpoint-example");
System.out.println("Trying to access piece of code...");
if (checkpoint.isEnabled()) {
System.out.println("Piece of code already executed");
}
else {
System.out.println("Piece of code executed for the first time");
checkpoint.enable();
}
System.out.println("...");
while (true) {
}
[...]
Process one
$ java CheckpointExample
Trying to access piece of code...
Piece of code executed for the first time
...
Process two
$ java CheckpointExample
Trying to access piece of code...
Piece of code already executed
...
Property | Parameter type | Return type | Description | Default parameter value |
---|---|---|---|---|
enable | void |
void |
Starts a new checkpoint | - |
disable | void |
void |
Disables checkpoint | - |
exists | void |
boolean |
Checks if a checkpoint was created. | - |
isEnabled | void |
boolean |
Checks if the checkpoint is active. | - |
delete | void |
void |
Checks if the checkpoint is active. | - |
Details about each version are documented in the releases section.
See the documentation on how you can contribute to the project here.
Name | Type | Description |
---|---|---|
dist | Directory |
Released versions |
docs | Directory |
Documentation files |
src | Directory |
Source files |