Skip to content

Commit 435af87

Browse files
committed
#78: Added shutdown() method to DefaultEnv to stop thread pools and updated Integration Guide and FAQ.
1 parent 39dd770 commit 435af87

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

docs/pages/faq.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ blank lines (or 33K including comments and blank lines).
160160

161161
### How many test cases are there?
162162

163-
There are currently over 11K individual test cases.
163+
There are currently over 11,000 individual test cases.
164164
Each test case is a Jactl script that is compiled, run, and then verified against the expected
165165
result (or the expected error).
166166

@@ -213,6 +213,18 @@ def decoded = x.base64Decode() // will be array of bytes: [1, 2, 3, 4]
213213
```
214214
See the [Integration Guide](integration-guide.md) for more information.
215215

216+
### Why doesn't my Java program exit after evaluating a Jactl script?
217+
218+
If you have a simple Java program where you evaluate a Jactl script using the default execution
219+
environment, there will be some daemon threads that have been started in the background and
220+
if you don't stop these threads, the JVM will not normally exit (unless `System.exit()` is called).
221+
222+
Note that these threads are shared and only started up once.
223+
224+
You can use the static method `io.jactl.DefaultEnv.shutdown()` to stop these threads.
225+
226+
See [Integration Guide](integration-guide.md) for more information.
227+
216228
### Is there an IntelliJ plugin for Jactl?
217229

218230
Yes, there is an IntelliJ plugin.

docs/pages/integration-guide.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,29 @@ All these exception classes are subclasses of the top level `io.jactl.JactlError
187187
> **Note**<br/>
188188
> All of these classes are unchecked exceptions so be sure to catch them at the appropriate place in your code.
189189
190+
### Default Execution Environment and Shutdown
191+
192+
By default, if you have not provided an implementation of the `JactlEnv` interface
193+
(see [Jactl Execution Environment](#jactl-execution-environment) below) you will be using the
194+
built-in `io.jactl.DefaultEnv`.
195+
196+
This class creates static thread pools for the non-blocking event loop threads, the blocking
197+
threads, and a thread for timers.
198+
199+
Since these thread-pools are daemon threads, if you want to cleanly exit without invoking
200+
`System.exit()`, you will need stop these thread-pools using the static `io.jactl.DefaultEnv.shutdown()`
201+
method:
202+
203+
```java
204+
class MyTest {
205+
public static void main(String[] args) {
206+
Object result = Jactl.eval("3 + 5");
207+
System.out.println("Result is " + result);
208+
io.jactl.DefaultEnv.shutdown();
209+
}
210+
}
211+
```
212+
190213
## JactlContext
191214

192215
Although most of the examples shown so far haven't used a JactlContext, in general, you will need to create an object

src/main/java/io/jactl/DefaultEnv.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,10 @@ public void scheduleBlocking(Runnable blocking) {
6565
public Object getThreadContext() {
6666
return null;
6767
}
68+
69+
public static void shutdown() {
70+
eventLoop.shutdown();
71+
blockingExecutor.shutdown();
72+
timerService.shutdown();
73+
}
6874
}

0 commit comments

Comments
 (0)