File tree 2 files changed +15
-6
lines changed
src/main/java/com/caoccao/javet/interop
2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -83,9 +83,11 @@ public final class V8Guard implements IJavetClosable {
83
83
*/
84
84
public void cancel () {
85
85
if (!isClosed ()) {
86
- PriorityBlockingQueue <V8Guard > v8GuardQueue = v8Runtime .getV8Host ().getV8GuardDaemon ().getV8GuardQueue ();
87
- boolean ignored = v8GuardQueue .remove (this );
88
86
closed = true ;
87
+ synchronized (v8Runtime .getCloseLock ()) {
88
+ PriorityBlockingQueue <V8Guard > v8GuardQueue = v8Runtime .getV8Host ().getV8GuardDaemon ().getV8GuardQueue ();
89
+ boolean ignored = v8GuardQueue .remove (this );
90
+ }
89
91
}
90
92
}
91
93
Original file line number Diff line number Diff line change @@ -573,7 +573,7 @@ public void run() {
573
573
if (!(!v8Guard .isDebugModeEnabled () && IS_IN_DEBUG_MODE )) {
574
574
V8Runtime v8Runtime = v8Guard .getV8Runtime ();
575
575
synchronized (v8Runtime .getCloseLock ()) {
576
- if (!v8Runtime .isClosed () && v8Runtime .isInUse ()) {
576
+ if (!v8Guard . isClosed () && ! v8Runtime .isClosed () && v8Runtime .isInUse ()) {
577
577
v8Runtime .terminateExecution ();
578
578
v8Runtime .getLogger ().logWarn (
579
579
"Execution was terminated after {0}ms." ,
@@ -582,9 +582,16 @@ public void run() {
582
582
}
583
583
}
584
584
} else {
585
- v8GuardQueue .add (v8Guard );
586
- long sleepMillis = Math .min (v8Guard .getEndTimeMillis () - now , sleepIntervalMillis );
587
- TimeUnit .MILLISECONDS .sleep (sleepMillis );
585
+ V8Runtime v8Runtime = v8Guard .getV8Runtime ();
586
+ synchronized (v8Runtime .getCloseLock ()) {
587
+ if (!v8Guard .isClosed () && !v8Runtime .isClosed ()) {
588
+ v8GuardQueue .add (v8Guard );
589
+ long sleepMillis = Math .min (v8Guard .getEndTimeMillis () - now , sleepIntervalMillis );
590
+ if (sleepMillis > 0 ) {
591
+ TimeUnit .MILLISECONDS .sleep (sleepMillis );
592
+ }
593
+ }
594
+ }
588
595
}
589
596
} catch (InterruptedException ignored ) {
590
597
break ;
You can’t perform that action at this time.
0 commit comments