Thread Component
com.eu.habbo.core.threading.ThreadComponent
The ThreadComponent class in the Arcturus project is responsible for managing threads and executing tasks asynchronously. This documentation will guide you on how to access and use the different methods provided by this component.
Accessing the Thread Component
To access the Thread Component instance, you need to use the Emulator class. Here's an example of how you can do it:
ThreadComponent threads = Emulator.getComponent(ThreadComponent.class);Methods
The ThreadComponent class provides the following methods:
run
Future<Void> run(Runnable run)Executes the given Runnable task asynchronously using the virtual thread pool. Returns a Future representing the pending completion of the task.
run with Delay
ScheduledFuture<?> run(Runnable run, long delay)Schedules the given Runnable task to be executed after the specified delay in milliseconds. Returns a ScheduledFuture representing the pending completion of the task.
getSchedule
ScheduledExecutorService getSchedule()Returns the scheduled executor service used by the thread component.
Note: Please refer to the code comments for detailed explanations and use cases of each method.
Example Usage
Here's an example of how you can use the ThreadComponent methods:
// First get the thread component
ThreadComponent threads = Emulator.getComponent(ThreadComponent.class);
// Run a task asynchronously
Future<Void> future = threads.run(() -> {
// Code to be executed asynchronously
});
// Schedule a task to run after a delay
ScheduledFuture<?> scheduledFuture = threads.run(() -> {
// Code to be executed after the specified delay
}, 5000);