Skip to content

Commit 904c770

Browse files
committed
Allow scripts to be optionally interrupted during dispose()
1 parent 7570351 commit 904c770

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[1.5.2]
2+
- Allow scripts to be optionally interrupted during dispose()
3+
14
[1.5.1]
25
- Only allow currently executing scripts to finish during shutdown. Any other queued scripts will be skipped.
36
- Add methods to cancel queued and running futures without sending skip event

core/src/main/java/org/mini2Dx/miniscript/core/DefaultThreadPoolProvider.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)
6363
}
6464

6565
@Override
66-
public void shutdown() {
67-
executorService.shutdown();
66+
public void shutdown(boolean interruptThreads) {
67+
if(interruptThreads) {
68+
executorService.shutdownNow();
69+
} else {
70+
executorService.shutdown();
71+
}
6872
}
6973
}

core/src/main/java/org/mini2Dx/miniscript/core/GameScriptingEngine.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,21 @@ public void run() {
213213
* Shuts down the thread pool and cleans up resources
214214
*/
215215
public void dispose() {
216+
dispose(false);
217+
}
218+
219+
/**
220+
* Shuts down the thread pool and cleans up resources
221+
* @param interruptScripts True if running scripts should be interrupted
222+
*/
223+
public void dispose(boolean interruptScripts) {
216224
shuttingDown.set(true);
217225

218226
if(cleanupTask != null) {
219227
cleanupTask.cancel(false);
220228
cleanupTask = null;
221229
}
222-
threadPoolProvider.shutdown();
230+
threadPoolProvider.shutdown(interruptScripts);
223231
}
224232

225233
/**

core/src/main/java/org/mini2Dx/miniscript/core/ThreadPoolProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public interface ThreadPoolProvider {
1515

1616
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit);
1717

18-
void shutdown();
18+
void shutdown(boolean interruptThreads);
1919

2020
}

0 commit comments

Comments
 (0)