• Home
    • View
    • Login
    This page
    • Normal
    • Export PDF
    • Export Word
    • Attachments
    • Page Information

    Loading...
  1. Dashboard
  2. Loom
  3. Main
  4. Structured Concurrency

Page History

Versions Compared

Old Version 40

changes.mady.by.user Alan Bateman

Saved on Jan 20, 2020

compared with

New Version Current

changes.mady.by.user Alan Bateman

Saved on Jun 06, 2020

  • Previous Change: Difference between versions 39 and 40
  • View Page History

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

ThreadFactory factory = Thread.builder().virtual().factory()
try (ExecutorService executor = Executors.newUnboundedExecutornewThreadExecutor(factory)) {
    executor.submit(task1);
    executor.submit(task2);
}

...

try (ExecutorService executor = Executors.newUnboundedExecutornewVirtualThreadExecutor(factory)) {
executor.submit(() -> foo());
executor.submit(() -> bar());
}

void foo() {
    try (ExecutorService executor = Executors.newUnboundedExecutornewVirtualThreadExecutor(factory)) {
        executor.submit(...);
}
}

void bar() {
    try (ExecutorService executor = Executors.newUnboundedExecutornewVirtualThreadExecutor(factory)) {
        executor.submit(...);
    }

}

...

An ExecutorService can be wrapped with a deadline so that running tasks are stopped (by interruption) when the deadline expires before the executor has terminated.


ThreadFactory factory = Thread.builder().virtual().factory()
var deadline = Instant.now().plusSeconds(2);
try (ExecutorService executor = Executors.newUnboundedExectornewVirtualThreadExector(factory).withDeadline(deadline)) {
    executor.submit(task1);
    executor.submit(task2);
}

...


try (ExecutorService executor1 = Executors.newUnboundedExecutornewVirtualThreadExecutor(factory).withDeadline(deadline)) {
try (ExecutorService executor2 = Executors.newUnboundedExecutornewVirtualThreadExecutor(factory)) {
executor2.submit(task1);
executor2.submit(task2);
}
}

...

Overview
Content Tools
ThemeBuilder

Terms of Use • License: GPLv2 • Privacy • Trademarks • Contact Us

Powered by a free Atlassian Confluence Open Source Project License granted to https://www.atlassian.com/software/views/opensource-community-additional-license-offer. Evaluate Confluence today.

  • Adaptavist ThemeBuilder Powered by Atlassian Confluence 7.4.1
  • Adaptavist ThemeBuilder printed.by.atlassian.confluence
  • Report a bug
  • Atlassian News
Atlassian
Adaptavist ThemeBuilder EngineAtlassian Confluence
{"serverDuration": 296, "requestCorrelationId": "d09f67b3e1b6bad1"}