Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual threads #2

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,47 +181,44 @@ public void setUp() throws IOException {
openAPI = getOpenAPI(RESOURCE_PATH);
}

@Param({"10", "100", "1000", "5000", "10000"})
// @Param({"10", "100", "1000"})
@Param({"10"})
private int numThreads;

@Test(description = "it should clone everything concurrently")
@Benchmark
public void cloneEverythingConcurrent() throws IOException {
ThreadGroup tg = new ThreadGroup("SpecFilterTest" + "|" + System.currentTimeMillis());
Thread[] threads = new Thread[numThreads];
final Map<String, OpenAPI> filteredMap = new ConcurrentHashMap<>();
for (int i = 0; i < numThreads; i++) {
final int id = i;
new Thread(tg, "SpecFilterTest") {
public void run() {
try {
filteredMap.put("filtered " + id, new SpecFilter().filter(openAPI, new NoOpOperationsFilter(), null, null, null));
} catch (Exception e) {
e.printStackTrace();
}
threads[i] = Thread.ofVirtual().name("SpecFilterTest").start(() -> {
try {
filteredMap.put("filtered " + id, new SpecFilter().filter(openAPI, new NoOpOperationsFilter(), null, null, null));
} catch (Exception e) {
e.printStackTrace();
}
}.start();
});
}

new Thread(new FailureHandler(tg, filteredMap, openAPI)).start();
Thread.ofVirtual().start(new FailureHandler(threads, filteredMap, openAPI));
}

class FailureHandler implements Runnable {
ThreadGroup tg;
Thread[] threads;
Map<String, OpenAPI> filteredMap;
private OpenAPI openAPI;

private FailureHandler(ThreadGroup tg, Map<String, OpenAPI> filteredMap, OpenAPI openAPI) {
this.tg = tg;
private FailureHandler(Thread[] threads, Map<String, OpenAPI> filteredMap, OpenAPI openAPI) {
this.threads = threads;
this.filteredMap = filteredMap;
this.openAPI = openAPI;
}

@Override
public void run() {
try {
Thread[] thds = new Thread[tg.activeCount()];
tg.enumerate(thds);
for (Thread t : thds) {
for (Thread t : threads) {
if (t != null) {
t.join(10000);
}
Expand Down
Loading