-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Internal feature toggle to disable virtual threads (#521)
* toggle to swap between virtual and physical threads * creating system property
- Loading branch information
Showing
7 changed files
with
47 additions
and
10 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
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
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
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
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,14 @@ | ||
package com.mageddo.utils; | ||
|
||
import com.mageddo.commons.concurrent.ThreadPool; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
|
||
public class Executors { | ||
public static ExecutorService newThreadExecutor() { | ||
if (Boolean.getBoolean("mg.physical_threads.active")) { | ||
return ThreadPool.newFixed(50); | ||
} | ||
return java.util.concurrent.Executors.newVirtualThreadPerTaskExecutor(); | ||
} | ||
} |
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
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,23 @@ | ||
package com.mageddo.utils; | ||
|
||
import lombok.SneakyThrows; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class ExecutorsTest { | ||
|
||
@Test | ||
@SneakyThrows | ||
void virtualThreadsActiveByDefault() { | ||
// arrange | ||
try (final var executor = Executors.newThreadExecutor()) { | ||
// act | ||
final var isVirtual = executor.submit(() -> Thread.currentThread().isVirtual()).get(); | ||
|
||
// assert | ||
assertTrue(isVirtual); | ||
} | ||
|
||
} | ||
} |