You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -349,9 +349,9 @@ for (int i = 0; i < SOME_LARGE_SIZE; i++) {
349
349
}
350
350
```
351
351
352
-
It's up to library user to select how often to check the flag: there are always trade-offs between overhead for regular execution time (when execution is not cancelled) and the delay before thread react on cancellation. In the example above the check may be moved from inner loop to the outer loop - this will speed-up normal execution path but the code will react on cancellation with delay.
352
+
It's up to library user to select how often to check the flag: there are always trade-offs between overhead for regular execution time (when execution is not cancelled) and the delay before thread react on cancellation. In the example above the check may be moved from the inner loop to the outer loop - this will speed-up normal execution path but the code will react on the cancellation with delay.
353
353
354
-
Some API provides good built-in points for checks of early exits, the good example is [java.nio.file.FileVisitor](https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileVisitor.html) + [java.nio.file.Files walkFileTree](https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#walkFileTree(java.nio.file.Path,%20java.nio.file.FileVisitor). Here you can just put checks in `previsitDirectory` / `visitFile`:
354
+
Some API provides good built-in points to check for early exit, the good example is [java.nio.file.FileVisitor](https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileVisitor.html) + [java.nio.file.Files walkFileTree](https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#walkFileTree(java.nio.file.Path,%20java.nio.file.FileVisitor). Here you can just put checks in `previsitDirectory` / `visitFile`:
355
355
356
356
```java
357
357
@Test
@@ -363,7 +363,8 @@ public void testReallife() throws Exception {
System.out.printf("[%d ms] [%s] Task#%d: visiting dir %s%n",
367
+
time.current(), Thread.currentThread(), id, dir);
367
368
if (Thread.currentThread().isInterrupted()) {
368
369
// STOP when interrupted
369
370
returnFileVisitResult.TERMINATE;
@@ -385,7 +386,7 @@ public void testReallife() throws Exception {
385
386
386
387
2.You are using old blocking API of `java.io.InputStream` or `java.net.URLConnection`
387
388
Probably, your code uses old blocking streams from `java.io` like `java.io.FileInputStream` or `SocketInputStream` opened from `java.net.Socket`.Or you are using `java.net.URLConnection`.Or outdated blocking ApacheHTTPClient. These all prevents running thread from termination once interrupted -- all of these API-s are blocking and do not react on interruptions. The options are:
388
-
-If you are using some third-party synchronous networking library then try to replace it with asynchronous version. ForHTTP protocol there is a plenty of options like AsyncHttpClient and OkHttp. Both returns `CompletableFuture` as operation results and therefore could be easily plugged with the rest of TascalateConcurrent code.
389
+
-If you are using some third-party synchronous networking library then try to replace it with the asynchronous version. ForHTTP protocol there is a plenty of options like AsyncHttpClient and OkHttp. Both returns `CompletableFuture` as operation results and therefore could be easily plugged with the rest of TascalateConcurrent code.
389
390
-If you are using blocking file APItry to replace it with NIO version, it's the best option:
`BlockingIO.interruptible(...)` can wrap as interruptible all the functional interfaces used in `CompletionStage` / `Promise` API. The parameter to the `BlockingIO.register` should be any implementation of `java.lang.Closeable` that will be closed on thread interruption. For `InputStream` or `OutputStream` is just the stream itself. For `java.net.HttpUrlConnection` you can use
428
+
`BlockingIO.interruptible(...)` can wrap as interruptible all the functional interfaces used in `CompletionStage` / `Promise` API. The parameter to the `BlockingIO.register` should be any implementation of `java.lang.Closeable` that will be closed on thread interruption. For `InputStream` or `OutputStream` it is just the stream itself. For `java.net.HttpUrlConnection` you can use
0 commit comments