< prev index next >

test/jdk/java/lang/Thread/virtual/stress/PingPong.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

@@ -34,10 +34,11 @@
   * @requires vm.debug != true
   * @run main PingPong LTQ 500000
   */
  
  import java.time.Duration;
+ import java.time.Instant;
  import java.util.concurrent.SynchronousQueue;
  import java.util.concurrent.LinkedTransferQueue;
  import java.util.concurrent.atomic.AtomicInteger;
  
  public class PingPong {

@@ -89,15 +90,16 @@
          });
  
          boolean terminated;
          do {
              terminated = t1.join(Duration.ofMillis(500));
-             if (terminated)
+             if (terminated) {
                  terminated = t2.join(Duration.ofMillis(500));
-             System.out.format("%d %s%n", count1.get(), count2.get());
+             }
+             System.out.format("%s => T1 %d of %d, T2 %d of %d%n",
+                     Instant.now(), count1.get(), iterations, count2.get(), iterations);
          } while (!terminated);
- 
      }
  
      interface Exchanger<E> {
          void transfer (E value) throws InterruptedException;
          E take() throws InterruptedException;
< prev index next >