mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-27 20:45:27 +01:00
Added the ability to create a private thread.
This commit is contained in:
parent
1b17a8f24c
commit
4079893ea4
@ -7,12 +7,18 @@ import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
public class DataManagerAbstract {
|
||||
|
||||
protected final DatabaseConnector databaseConnector;
|
||||
protected final Plugin plugin;
|
||||
|
||||
private static Map<String, ScheduledExecutorService> threads = new HashMap<>();
|
||||
|
||||
public DataManagerAbstract(DatabaseConnector databaseConnector, Plugin plugin) {
|
||||
this.databaseConnector = databaseConnector;
|
||||
this.plugin = plugin;
|
||||
@ -61,4 +67,15 @@ public class DataManagerAbstract {
|
||||
public void sync(Runnable runnable) {
|
||||
Bukkit.getScheduler().runTask(this.plugin, runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue a task to be run synchronously on a new thread.
|
||||
*
|
||||
* @param runnable task to run on the next server tick
|
||||
* @param threadKey the thread key to run on.
|
||||
*/
|
||||
public void sync(Runnable runnable, String threadKey) {
|
||||
threads.computeIfAbsent(threadKey.toUpperCase(),
|
||||
t -> Executors.newSingleThreadScheduledExecutor()).execute(runnable);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user