Skip to content

Scheduling

龙卷锋 edited this page Jun 1, 2020 · 3 revisions

Scheduling

The use of the task scheduler module can reduce the dependence on the cron, and can be unified control management in the code, in order to help you get started, a simple example is defined

import hunt.concurrency.Executors;
import hunt.concurrency.Scheduler;
import hunt.concurrency.ScheduledThreadPoolExecutor;
import core.time;
import hunt.util.Common;

// Get executor
ScheduledThreadPoolExecutor executor = cast(ScheduledThreadPoolExecutor)Executors.newScheduledThreadPool(8);// Use 8 threads to process

// Create a task
executor.scheduleAtFixedRate(
	new class Runnable {
		void run() {
			// Do something

		}
	}
, 1.seconds, 600.seconds); // Delayed execution by 1 second, repeated execution at 600 second intervals

/**
* Initiates an orderly shutdown in which previously submitted
* tasks are executed, but no new tasks will be accepted.
* Invocation has no additional effect if already shut down.
**/
executor.shutdown();
Clone this wiki locally