Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Details
What you've changed
Description
Java 21 adds support for Project Loom's Virtual Threads, a new type of Thread that doesn't use an OS thread, rather a custom thread created by the JVM, therefore being useful for large quantities of Thread creation.
This PR updates the pom.xml to add support for Java 21, including updating other dependencies. It also updates the DiscordJarThreadAllocator class to create a new method,
requestVirtualThread
which will return a running virtual thread, similar to therequestThread
method.This should be backwards-compatible with older versions of Java, as discord.jar will check that the Java release version is 21 or higher before attempting to use virtual threads. It is, however, recommended that you do update your version, especially for larger applications or those with many intents enabled.
Virtual Threads are mainly intended to be used by the Gateway implementation but can also be included in other high throughput parts of the code.