Taskun Scheduler Framework Java Library User Guide Guide
Taskun Scheduler Framework Java Library User Guide Guide
Taskun Scheduler is a lightweight Java library for managing and scheduling tasks.It provides a simple and flexible way to perform timing tasks, allowing you to easily arrange and perform various types of tasks.
Here are steps and examples of using the Taskun Scheduler framework.
1. Introduce Taskun Scheduler Library
First, you need to add a Taskun Scheduler library to your project.You can obtain the latest version of the library from the central deposit storage or other available locations.
<dependency>
<groupId>io.github.akiraly.taskun</groupId>
<artifactId>taskun-core</artifactId>
<version>1.0.0</version>
</dependency>
2. Create task category
Next, you need to create a task class that will implement the `task` interface.This interface defines a `Run ()" method, you can write the task logic that needs to be executed in it.
public class MyTask implements Task {
@Override
public void run() {
// Execute the task logic
System.out.println ("Execute my task!"););
}
}
3. Create and configure the task scheduler
In your application, you need to create an `Taskscheduler` object to manage and schedule tasks.You can use the `taskschedulerbuilder` class for configuration.
TaskScheduler taskScheduler = TaskSchedulerBuilder.newBuilder()
.withtedpoolsize (5) // Configure the thread pool size
.build();
4. Arrange tasks
With the task scheduler, you can arrange various types of tasks to perform at a specific time or interval.Here are some examples:
-A arrange a one -time task (perform once at the specified time):
Task oneTimeTask = new MyTask();
taskScheduler.schedule(oneTimeTask, LocalDateTime.of(2021, Month.JANUARY, 1, 12, 0, 0));
-A arrange a circular task (execute according to a certain interval after the designated time starts):
Task repeatingTask = new MyTask();
taskScheduler.scheduleAtFixedRate(repeatingTask, LocalDateTime.now(), Duration.ofMinutes(5));
-A arrange delay tasks (execute once after the specified time):
Task delayedTask = new MyTask();
taskScheduler.scheduleWithDelay(delayedTask, Duration.ofHours(1));
5. Start the task scheduler
After setting the task, you need to start the task scheduler to start the task.
taskScheduler.start();
6. Stop the task scheduler
If you need to stop the task scheduler, you can use the following code:
taskScheduler.stop();
This is a simple Taskun SCHeduler framework Java class library use guide.By following the above steps, you can easily create and arrange tasks to achieve the management and scheduling of timing tasks.Corresponding configuration and expansion according to your actual needs and business logic.
I hope this guide will help you use Taskun SCHEDULER framework!