Skip to content

Does GraalVM polyglot api support "interuptions" #9317

Answered by chumer
walksanatora asked this question in Q&A
Discussion options

You must be logged in to vote

You can interrupt any execution of polyglot code with Context.interrupt() from any thread (for example a timer). But that will trigger an exception in the polyglot code, so resuming at the same location is not easily possible. You would need to take care of resuming yourself.

Here is a quick example of how to interrupt JavaScript guest execution:

public static void main(String[] args) throws ReflectiveOperationException {
	var timer = new java.util.Timer(true);
	try (Context c = Context.create()) {
		timer.schedule(new TimerTask() {
			@Override
			public void run() {
				// maximum interruption time
				try {
					c.interrupt(Duration.ofMinutes(5));
				} catch (TimeoutException e) {
					

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by alina-yur
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@sgammon
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants