Last active
January 15, 2022 14:58
-
-
Save blablubbabc/e884c114484f34cae316c48290b21d8e to your computer and use it in GitHub Desktop.
Revisions
-
blablubbabc revised this gist
Jan 15, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ public void onDisable() { boolean asyncTasksTimeout = false; while (this.getActiveAsyncTasks() > 0) { try { Thread.sleep(25); } catch (InterruptedException e) { e.printStackTrace(); } -
blablubbabc renamed this gist
May 12, 2016 . 1 changed file with 13 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ // inside the plugin class private static final long ASYNC_TASKS_TIMEOUT_SECONDS = 10; @Override @@ -9,21 +9,21 @@ public void onDisable() { boolean asyncTasksTimeout = false; while (this.getActiveAsyncTasks() > 0) { try { Thread.sleep(5); } catch (InterruptedException e) { e.printStackTrace(); } // after timeout disable anyways..: if (System.currentTimeMillis() - asyncTasksStart > asyncTasksTimeoutMillis) { asyncTasksTimeout = true; this.getLogger().warning("Waited " + ASYNC_TASKS_TIMEOUT_SECONDS + " seconds for " + this.getActiveAsyncTasks() + " remaining async tasks to complete. Disabling now anyways.."); break; } } final long asyncTasksTimeWaited = System.currentTimeMillis() - asyncTasksStart; if (!asyncTasksTimeout && asyncTasksTimeWaited > 1) { this.getLogger().info("Waited " + asyncTasksTimeWaited + " ms for async tasks to finish."); } } -
blablubbabc created this gist
May 12, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ # inside plugin class private static final long ASYNC_TASKS_TIMEOUT_SECONDS = 10; @Override public void onDisable() { // wait for async tasks to complete: final long asyncTasksTimeoutMillis = ASYNC_TASKS_TIMEOUT_SECONDS * 1000; final long asyncTasksStart = System.currentTimeMillis(); boolean asyncTasksTimeout = false; while (this.getActiveAsyncTasks() > 0) { try { Thread.sleep(5); } catch (InterruptedException e) { e.printStackTrace(); } // after timeout disable anyways..: if (System.currentTimeMillis() - asyncTasksStart > asyncTasksTimeoutMillis) { asyncTasksTimeout = true; this.getLogger().warning("Waited " + ASYNC_TASKS_TIMEOUT_SECONDS + " seconds for " + this.getActiveAsyncTasks() + " remaining async tasks to complete. Disabling now anyways.."); break; } } final long asyncTasksTimeWaited = System.currentTimeMillis() - asyncTasksStart; if (!asyncTasksTimeout && asyncTasksTimeWaited > 1) { this.getLogger().info("Waited " + asyncTasksTimeWaited + " ms for async tasks to finish."); } } private int getActiveAsyncTasks() { int workers = 0; for (BukkitWorker worker : Bukkit.getScheduler().getActiveWorkers()) { if (worker.getOwner().equals(this)) { workers++; } } return workers; }