From 713263214f41738c9bfa57f35fcaf580193812aa Mon Sep 17 00:00:00 2001 From: Keir Nellyer Date: Sun, 24 Apr 2016 17:15:12 +0100 Subject: [PATCH] Run ReportPurgeTask asynchronously This prevents the task from hanging the server which may be an issue when a large amount of reports exist. --- .../Mineplex.Core/src/mineplex/core/report/ReportPlugin.java | 3 +-- .../src/mineplex/core/report/task/ReportPurgeTask.java | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java index 0bcfc8cef..97c771422 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java @@ -26,9 +26,8 @@ public class ReportPlugin extends MiniPlugin _reportManager = reportManager; // purge old reports every minute - // TODO does this need to be async? _reportPurgeTask = new ReportPurgeTask(_reportManager); - _reportPurgeTask.runTaskTimer(getPlugin(), 20L * 10, 20L * 60); + _reportPurgeTask.runTaskTimerAsynchronously(getPlugin(), 20L * 10, 20L * 60); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/task/ReportPurgeTask.java b/Plugins/Mineplex.Core/src/mineplex/core/report/task/ReportPurgeTask.java index 558d67f76..644fc1726 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/task/ReportPurgeTask.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/task/ReportPurgeTask.java @@ -1,5 +1,7 @@ package mineplex.core.report.task; +import java.util.ArrayList; + import org.bukkit.scheduler.BukkitRunnable; import mineplex.core.common.util.C; @@ -21,7 +23,7 @@ public class ReportPurgeTask extends BukkitRunnable @Override public void run() { - for (int reportId : _reportManager.getActiveReports()) + for (int reportId : new ArrayList<>(_reportManager.getActiveReports())) // create copy as this will be run async { Report report = _reportManager.getReport(reportId);