-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fc00e2
commit 776e648
Showing
6 changed files
with
558 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
loom-compatibility/src/loom_compatibility/LoomExecutors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package loom_compatibility; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.ThreadFactory; | ||
|
||
public interface LoomExecutors { | ||
|
||
static LoomExecutors load() throws LoomUnavailable { | ||
try { | ||
return new LoomExecutorsImplementation(); | ||
} catch (LinkageError e) { | ||
throw new LoomUnavailable(e); | ||
} | ||
} | ||
|
||
/** | ||
* Creates an Executor that starts a new Thread for each task. | ||
* The number of threads created by the Executor is unbounded. | ||
* | ||
* <p> Invoking {@link Future#cancel(boolean) cancel(true)} on a {@link | ||
* Future Future} representing the pending result of a task submitted to | ||
* the Executor will {@link Thread#interrupt() interrupt} the thread | ||
* executing the task. | ||
* | ||
* @param threadFactory the factory to use when creating new threads | ||
* @return a new executor that creates a new Thread for each task | ||
* @throws NullPointerException if threadFactory is null | ||
* @since 21 | ||
*/ | ||
public ExecutorService newThreadPerTaskExecutor(ThreadFactory threadFactory); | ||
|
||
/** | ||
* Creates an Executor that starts a new virtual Thread for each task. | ||
* The number of threads created by the Executor is unbounded. | ||
* | ||
* <p> This method is equivalent to invoking | ||
* {@link #newThreadPerTaskExecutor(ThreadFactory)} with a thread factory | ||
* that creates virtual threads. | ||
* | ||
* @return a new executor that creates a new virtual Thread for each task | ||
* @since 21 | ||
*/ | ||
public ExecutorService newVirtualThreadPerTaskExecutor(); | ||
} |
20 changes: 20 additions & 0 deletions
20
loom-compatibility/src/loom_compatibility/LoomExecutorsImplementation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package loom_compatibility; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.ThreadFactory; | ||
|
||
class LoomExecutorsImplementation implements LoomExecutors { | ||
static { | ||
Thread.ofVirtual(); | ||
} | ||
|
||
@Override | ||
public ExecutorService newThreadPerTaskExecutor(ThreadFactory threadFactory) { | ||
return java.util.concurrent.Executors.newThreadPerTaskExecutor(threadFactory); | ||
} | ||
|
||
@Override | ||
public ExecutorService newVirtualThreadPerTaskExecutor() { | ||
return java.util.concurrent.Executors.newVirtualThreadPerTaskExecutor(); | ||
} | ||
} |
Oops, something went wrong.