Hey,
as I know, it’s better, when I create a new thread for “heavy” calculations in combination with database connections.
The scheduler is placed in a new class, which gets called / created on GameStartedServerEvent
with new TaxScheduler(this, logger);
Scheduler class:
public TaxScheduler(Main plugin, Logger logger) throws IOException {
Scheduler scheduler = Sponge.getGame().getScheduler();
Task.Builder taskBuilder = scheduler.createTaskBuilder();
taskBuilder.execute(new Runnable() {
public void run() {
//code
}
}).interval(60, TimeUnit.SECONDS).name("Tax Updater").submit(plugin);
}
My code works, but I want to open it in a new thread. I did this before, but I’m new to java and don’t know the best way to do this.
Is there a better way, or is it “ok”, when I do it like this:
new Thread()
{
public void run() {
try {
new TaxScheduler(plugin, logger);
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
Greets