Monitor your JTcl application

Java Management eXtensions (JMX) makes it easy to add monitoring capabilities to your application running under the JTcl Interpreter.

First, you'll need to be sure to start JTcl with JVM flags that enable the builtin JMX server:

 -Dcomagement.jmxremote.ssl=false \"
export JAVA_OPTS

Here is a sample script that creates a Java MBean, registers it with the JMX server, and updates the value periodically:

package require hyde

# define a Java interface and static inner class that follows Java MBean
# conventions.  This example only allows a counter to be read.  JMX allows
# bean properties be set and  methods invoked.

hyde::jclass JMX {
   public interface JTclStatsMBean {
       public int getCounter();
   public static class JTclStats implements JTclStatsMBean {
       private int counter;
       public void setCounter(int i) {counter = i;}
       public int  getCounter()      {return counter;}

# create a new bean object
set tclstats [java::new hyde.JMX.JTclStats]

# get a reference to the JVM's JMX server
set mbs [java::call getPlatformMBeanServer]

# create a domain, key, and name for our bean
set obj [java::new JTcl JTclStats bean_1]

# register our bean and object name with the jmx server
$mbs registerMBean $tclstats $obj

# now update the bean as needed by the application
for {set i 1} {$i < 100} {incr i} {
    $tclstats setCounter $i
    after 5000


To monitor your application, use VisualVM , jvisualvm or jconsole (the latter two are shipped with your Java JDK.) When using VisualVM or jvisualvm, you will need to add the VisualVM-MBeans plugin by accessing the Tools -> Plugins menu.

Here's what the above script looks like in VisualVM:


Monitoring an application on a remote machine requires either changing the property to a known port instead of an ephemeral port (as specified by 0), or to run the jstatd program on the remote machine (also included in the Java JDK.)

To run jstatd, you will first need a Java policy file, e.g., jstatd.all.policy:

grant {

Start jstatd with the policy file:

jstatd  -J-Djava.rmi.server.hostname= &

Replace the hostname ip address with the ip address of the machine on which jstatd is running (this works around an issue where the jstatd RMI registry might not be seen from another machine.) Using VisualVM, add a remote machine to see and monitor the applications running on that machine.