< prev index next >

test/jdk/java/lang/Thread/ThreadStateController.java

Print this page
rev 51731 : imported patch 8210732


  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.util.concurrent.Phaser;
  25 import java.util.concurrent.TimeUnit;
  26 import java.util.concurrent.TimeoutException;
  27 import java.util.concurrent.atomic.AtomicInteger;
  28 import java.util.concurrent.locks.LockSupport;
  29 
  30 import jdk.test.lib.LockFreeLogger;
  31 import jdk.testlibrary.Utils;
  32 
  33 /**
  34  * ThreadStateController allows a thread to request this thread to transition
  35  * to a specific thread state.  The {@linkplain #transitionTo request} is
  36  * a blocking call that the calling thread will wait until this thread is about
  37  * going to the new state.  Only one request of state transition at a time
  38  * is supported (the Phaser expects only parties of 2 to arrive and advance
  39  * to next phase).
  40  */
  41 public class ThreadStateController extends Thread {
  42     // used to achieve waiting states
  43     private final Object lock;
  44     public ThreadStateController(String name, Object lock) {
  45         super(name);
  46         this.lock = lock;
  47     }
  48 
  49     public void checkThreadState(Thread.State expected) {
  50         // maximum number of retries when checking for thread state.
  51         final int MAX_RETRY = 500;




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.util.concurrent.Phaser;
  25 import java.util.concurrent.TimeUnit;
  26 import java.util.concurrent.TimeoutException;
  27 import java.util.concurrent.atomic.AtomicInteger;
  28 import java.util.concurrent.locks.LockSupport;
  29 
  30 import jdk.test.lib.LockFreeLogger;
  31 import jdk.test.lib.Utils;
  32 
  33 /**
  34  * ThreadStateController allows a thread to request this thread to transition
  35  * to a specific thread state.  The {@linkplain #transitionTo request} is
  36  * a blocking call that the calling thread will wait until this thread is about
  37  * going to the new state.  Only one request of state transition at a time
  38  * is supported (the Phaser expects only parties of 2 to arrive and advance
  39  * to next phase).
  40  */
  41 public class ThreadStateController extends Thread {
  42     // used to achieve waiting states
  43     private final Object lock;
  44     public ThreadStateController(String name, Object lock) {
  45         super(name);
  46         this.lock = lock;
  47     }
  48 
  49     public void checkThreadState(Thread.State expected) {
  50         // maximum number of retries when checking for thread state.
  51         final int MAX_RETRY = 500;


< prev index next >