Run ReportPurgeTask asynchronously

This prevents the task from hanging the server which may be an issue
when a large amount of reports exist.
This commit is contained in:
Keir Nellyer 2016-04-24 17:15:12 +01:00
parent 57e9cd6e19
commit 713263214f
2 changed files with 4 additions and 3 deletions

View File

@ -26,9 +26,8 @@ public class ReportPlugin extends MiniPlugin
_reportManager = reportManager; _reportManager = reportManager;
// purge old reports every minute // purge old reports every minute
// TODO does this need to be async?
_reportPurgeTask = new ReportPurgeTask(_reportManager); _reportPurgeTask = new ReportPurgeTask(_reportManager);
_reportPurgeTask.runTaskTimer(getPlugin(), 20L * 10, 20L * 60); _reportPurgeTask.runTaskTimerAsynchronously(getPlugin(), 20L * 10, 20L * 60);
} }
@Override @Override

View File

@ -1,5 +1,7 @@
package mineplex.core.report.task; package mineplex.core.report.task;
import java.util.ArrayList;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
@ -21,7 +23,7 @@ public class ReportPurgeTask extends BukkitRunnable
@Override @Override
public void run() 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); Report report = _reportManager.getReport(reportId);