TruffleThreadBuilder
public final class TruffleThreadBuilder- Inheritance
ObjectTruffleThreadBuilder
A builder for threads that have access to the appropriate TruffleContext. The context is either the one that corresponds to the language environment that was used to create the builder, or the one specified by TruffleThreadBuilder.context(TruffleContext). The method TruffleLanguage.Env.newTruffleThreadBuilder(Runnable) is the only way to create the builder.
Threads without an associated context should be created by TruffleLanguage.Env.createSystemThread(Runnable).
Methods7
TruffleThreadBuilder context(TruffleContext)
context
since 23.1public TruffleThreadBuilder context(TruffleContext innerContext)Specifies TruffleContext for the threads created by the builder. It has to be an inner context created by TruffleLanguage.Env.newInnerContextBuilder(String...).build(). If not specified, the context associated with the language environment that created this builder is used (TruffleLanguage.Env.getContext()).
Threads without an associated context should be created by TruffleLanguage.Env.createSystemThread(Runnable).
Parameters
innerContextTruffleContextTruffleContextfor the threads created by this builder.
Returns
TruffleThreadBuilder- No description.
TruffleThreadBuilder threadGroup(ThreadGroup)
threadGroup
since 23.1public TruffleThreadBuilder threadGroup(ThreadGroup g)Specifies thread group for the threads created by this builder.
Parameters
gThreadGroup- thread group for the threads created by this builder.
Returns
TruffleThreadBuilder- No description.
TruffleThreadBuilder stackSize(long)
stackSize
since 23.1public TruffleThreadBuilder stackSize(long size)Specifies stack size for the threads created by this builder. The default is 0 which means that the parameter is ignored.
Parameters
sizelong- stack size for the threads created by this builder.
Returns
TruffleThreadBuilder- No description.
TruffleThreadBuilder beforeEnter(Runnable)
beforeEnter
since 23.1public TruffleThreadBuilder beforeEnter(Runnable r)Specifies before enter notification for the threads created by this builder. The notification runnable is invoked on the thread when the threads starts before the context is entered on the thread.
The default value for the notification runnable is null which means that no notification is executed.
If the notification runnable throws an exception, it is propagated up and can be handled by an uncaught exception handler
Parameters
rRunnable- before enter notification runnable for the threads created by this builder.
Returns
TruffleThreadBuilder- No description.
TruffleThreadBuilder afterLeave(Runnable)
afterLeave
since 23.1public TruffleThreadBuilder afterLeave(Runnable r)Specifies after leave notification for the threads created by this builder. The notification runnable is invoked on the thread after the thread leaves the context for the last time, i.e. the thread is about to finish.
The default value for the notification runnable is null which means that no notification is executed.
If the notification runnable throws an exception, it is propagated up and can be handled by an uncaught exception handler
Parameters
rRunnable- after leave notification runnable for the threads created by this builder.
Returns
TruffleThreadBuilder- No description.
TruffleThreadBuilder virtual(boolean)
virtual
since 24.1public TruffleThreadBuilder virtual(boolean v)Specifies whether to create a virtual thread (Thread#ofVirtual()) or a regular platform thread (the default) for the threads created by this builder.
Parameters
vboolean- whether to create a virtual thread.
Returns
TruffleThreadBuilder- No description.
Thread build()
build
since 23.1public Thread build()Creates a new thread based on the parameters specified by this builder. The thread is initialized when it is started, and finalized and disposed when it finishes its execution.
It is recommended to set an uncaught exception handler for the created thread. For example the thread can throw an uncaught exception if one of the initialized language contexts don't support execution on this thread.
The language that created and started the thread is responsible to stop and join it during the finalizeContext, otherwise an internal error is thrown. It's not safe to use the ExecutorService.awaitTermination(long, java.util.concurrent.TimeUnit) to detect Thread termination as the polyglot thread may be cancelled before executing the executor worker.
A typical implementation looks like: TruffleLanguageSnippets.AsyncThreadLanguage.finalizeContext
Returns
Thread- No description.