コード例 #1
0
 @Test
 public void testRun() throws Exception {
   StoptableThread thread = new TestThread();
   thread.start();
   ThreadUtils.sleep(5);
   System.out.println("before stop");
   thread.stopSafely();
   System.out.println("after stop");
   ThreadUtils.sleep(5);
 }
コード例 #2
0
  @Test
  public void testIsBlocked() {
    StoptableThread thread = new TestThread2();
    thread.setMaxHeartbeatInterval(2);

    assertThat(thread.isBlocked()).isFalse();

    thread.start();

    assertThat(thread.isBlocked()).isFalse();

    ThreadUtils.sleep(1);
    assertThat(thread.isBlocked()).isFalse();

    ThreadUtils.sleep(1.5);

    assertThat(thread.isBlocked()).isTrue();
  }