diff --git a/tck/src/main/java/ee/jakarta/tck/concurrent/spec/ManagedThreadFactory/resourcedef/ManagedThreadFactoryDefinitionOnEJBServlet.java b/tck/src/main/java/ee/jakarta/tck/concurrent/spec/ManagedThreadFactory/resourcedef/ManagedThreadFactoryDefinitionOnEJBServlet.java index 36e73c82..b7906451 100644 --- a/tck/src/main/java/ee/jakarta/tck/concurrent/spec/ManagedThreadFactory/resourcedef/ManagedThreadFactoryDefinitionOnEJBServlet.java +++ b/tck/src/main/java/ee/jakarta/tck/concurrent/spec/ManagedThreadFactory/resourcedef/ManagedThreadFactoryDefinitionOnEJBServlet.java @@ -80,9 +80,6 @@ public void testManagedThreadFactoryDefinitionAllAttributesEJB() throws Throwabl ManagedThreadFactory threadFactory = InitialContext.doLookup("java:app/concurrent/EJBThreadFactoryA"); - IntContext.set(162); - StringContext.set("testManagedThreadFactoryDefinitionAllAttributesEJB-2"); - Thread thread1 = threadFactory.newThread(() -> {}); assertEquals(thread1.getPriority(), 4, "New threads must be created with the priority that is specified on " + @@ -90,7 +87,7 @@ public void testManagedThreadFactoryDefinitionAllAttributesEJB() throws Throwabl BlockingQueue results = new LinkedBlockingQueue(); - threadFactory.newThread(() -> { + Thread thread2 = threadFactory.newThread(() -> { results.add(Thread.currentThread().getPriority()); results.add(StringContext.get()); results.add(IntContext.get()); @@ -99,7 +96,12 @@ public void testManagedThreadFactoryDefinitionAllAttributesEJB() throws Throwabl } catch (Throwable x) { results.add(x); } - }).start(); + }); + + IntContext.set(162); + StringContext.set("testManagedThreadFactoryDefinitionAllAttributesEJB-2"); + + thread2.start(); assertEquals(results.poll(MAX_WAIT_SECONDS, TimeUnit.SECONDS), Integer.valueOf(4), "ManagedThreadFactory must start threads with the configured priority."); @@ -203,14 +205,8 @@ public void testParallelStreamBackedByManagedThreadFactoryEJB() throws Throwable ManagedThreadFactory threadFactory = InitialContext.doLookup("java:app/concurrent/EJBThreadFactoryA"); - IntContext.set(2000); - StringContext.set("testParallelStreamBackedByManagedThreadFactoryEJB-2"); - fj = new ForkJoinPool(4, threadFactory, null, false); - IntContext.set(3000); - StringContext.set("testParallelStreamBackedByManagedThreadFactoryEJB-3"); - ForkJoinTask> task = fj.submit(() -> { return Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9) .parallelStream() @@ -229,6 +225,9 @@ public void testParallelStreamBackedByManagedThreadFactoryEJB() throws Throwable .reduce(Integer::sum); }); + IntContext.set(3000); + StringContext.set("testParallelStreamBackedByManagedThreadFactoryEJB-3"); + Optional result = task.join(); assertEquals(result.get(), Integer.valueOf(9180), "Third-party context type IntContext must propagated to ForkJoin threads " + diff --git a/tck/src/main/java/ee/jakarta/tck/concurrent/spec/ManagedThreadFactory/resourcedef/ManagedThreadFactoryDefinitionServlet.java b/tck/src/main/java/ee/jakarta/tck/concurrent/spec/ManagedThreadFactory/resourcedef/ManagedThreadFactoryDefinitionServlet.java index 4cff5ba6..cb2e9325 100644 --- a/tck/src/main/java/ee/jakarta/tck/concurrent/spec/ManagedThreadFactory/resourcedef/ManagedThreadFactoryDefinitionServlet.java +++ b/tck/src/main/java/ee/jakarta/tck/concurrent/spec/ManagedThreadFactory/resourcedef/ManagedThreadFactoryDefinitionServlet.java @@ -70,17 +70,15 @@ public void testManagedThreadFactoryDefinitionAllAttributes() throws Throwable { ManagedThreadFactory threadFactory = InitialContext.doLookup("java:app/concurrent/ThreadFactoryA"); - IntContext.set(162); - StringContext.set("testManagedThreadFactoryDefinitionAllAttributes-2"); - - Thread thread1 = threadFactory.newThread(() -> {}); + Thread thread1 = threadFactory.newThread(() -> { + }); assertEquals(thread1.getPriority(), 4, "New threads must be created with the priority that is specified on " + "ManagedThreadFactoryDefinition"); BlockingQueue results = new LinkedBlockingQueue(); - threadFactory.newThread(() -> { + Thread thread2 = threadFactory.newThread(() -> { results.add(Thread.currentThread().getPriority()); results.add(StringContext.get()); results.add(IntContext.get()); @@ -89,7 +87,12 @@ public void testManagedThreadFactoryDefinitionAllAttributes() throws Throwable { } catch (Throwable x) { results.add(x); } - }).start(); + }); + + thread2.start(); + + IntContext.set(162); + StringContext.set("testManagedThreadFactoryDefinitionAllAttributes-2"); assertEquals(results.poll(MAX_WAIT_SECONDS, TimeUnit.SECONDS), Integer.valueOf(4), "ManagedThreadFactory must start threads with the configured priority."); @@ -193,14 +196,8 @@ public void testParallelStreamBackedByManagedThreadFactory() throws Throwable { ManagedThreadFactory threadFactory = InitialContext.doLookup("java:app/concurrent/ThreadFactoryA"); - IntContext.set(2000); - StringContext.set("testParallelStreamBackedByManagedThreadFactory-2"); - fj = new ForkJoinPool(4, threadFactory, null, false); - IntContext.set(3000); - StringContext.set("testParallelStreamBackedByManagedThreadFactory-3"); - ForkJoinTask> task = fj.submit(() -> { return Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9) .parallelStream() @@ -219,6 +216,9 @@ public void testParallelStreamBackedByManagedThreadFactory() throws Throwable { .reduce(Integer::sum); }); + IntContext.set(3000); + StringContext.set("testParallelStreamBackedByManagedThreadFactory-3"); + Optional result = task.join(); assertEquals(result.get(), Integer.valueOf(9180), "Third-party context type IntContext must propagated to ForkJoin threads " +