< prev index next >

test/jdk/java/lang/ScopedValue/StressStackOverflow.java

Print this page
*** 50,10 ***
--- 50,11 ---
  import java.lang.ScopedValue.CallableOp;
  import java.time.Duration;
  import java.util.concurrent.ThreadLocalRandom;
  import java.util.concurrent.StructureViolationException;
  import java.util.concurrent.StructuredTaskScope;
+ import java.util.concurrent.StructuredTaskScope.Joiner;
  import java.util.function.Supplier;
  
  public class StressStackOverflow {
      public static final ScopedValue<Integer> el = ScopedValue.newInstance();
  

*** 167,11 ***
  
      // Run op in a new thread. Platform or virtual threads are chosen at random.
      void runInNewThread(Runnable op) {
          var threadFactory
                  = (ThreadLocalRandom.current().nextBoolean() ? Thread.ofPlatform() : Thread.ofVirtual()).factory();
!         try (var scope = new StructuredTaskScope<>("", threadFactory)) {
              var handle = scope.fork(() -> {
                  op.run();
                  return null;
              });
              scope.join();
--- 168,11 ---
  
      // Run op in a new thread. Platform or virtual threads are chosen at random.
      void runInNewThread(Runnable op) {
          var threadFactory
                  = (ThreadLocalRandom.current().nextBoolean() ? Thread.ofPlatform() : Thread.ofVirtual()).factory();
!         try (var scope = StructuredTaskScope.open(Joiner.awaitAll(), cf -> cf.withThreadFactory(threadFactory))) {
              var handle = scope.fork(() -> {
                  op.run();
                  return null;
              });
              scope.join();

*** 184,11 ***
      }
  
      public void run() {
          try {
              ScopedValue.where(inheritedValue, 42).where(el, 0).run(() -> {
!                 try (var scope = new StructuredTaskScope<>()) {
                      try {
                          if (ThreadLocalRandom.current().nextBoolean()) {
                              // Repeatedly test Scoped Values set by ScopedValue::call(), get(), and run()
                              final var deepRecursion
                                  = new DeepRecursion(DeepRecursion.Behaviour.choose(ThreadLocalRandom.current()));
--- 185,11 ---
      }
  
      public void run() {
          try {
              ScopedValue.where(inheritedValue, 42).where(el, 0).run(() -> {
!                 try (var scope = StructuredTaskScope.open(Joiner.awaitAll())) {
                      try {
                          if (ThreadLocalRandom.current().nextBoolean()) {
                              // Repeatedly test Scoped Values set by ScopedValue::call(), get(), and run()
                              final var deepRecursion
                                  = new DeepRecursion(DeepRecursion.Behaviour.choose(ThreadLocalRandom.current()));
< prev index next >