Пример #1
0
  @Test
  public void thread() {
    Counter count = new Counter();

    assertThat(count.value(), is(0));

    (new MakerIncrement(count)).start();
    (new MakerDecrement(count)).start();

    assertThat(count.value(), is(0));
  }
Пример #2
0
  public static void main(String[] args) throws Exception {

    MBeanServer mserver = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = new ObjectName("cz.jalasoft.learning.jmx:type=Monitoring");

    // Monitoring mbean = new Monitoring(30);

    Counter counter = new Counter(40);
    MyDynamic dbean = new MyDynamic(counter);

    mserver.registerMBean(dbean, name);

    while (true) {

      Thread.sleep(1000);

      if (counter.value() <= 0) {
        break;
      }
      System.out.println("Counting down: " + counter.value());
      counter.decrement();
    }
  }