THD Command

So you’re developing an application. It works, but you question if it is efficient or not. That is where the THD command comes in. The THD command will show all of the threads that are active in each Java application that is running.

This command will also show other useful JVM information. Information such as the number of unique classes that have been loaded, the amount of memory that has been allocated to hold that class information, process time, heap memory usage, stack usage and class object memory usage.

Then each thread is listed showing its processor usage time, thread name, the class that implements the thread, parent thread, state and whether or not the thread is a daemon thread.

Lastly any Watchdog that has been activated is listed with its name, the action that will be carried out should the watchdog be triggered and how long until the watchdog will be triggered should it not be fed.

Here is a quick application that tests the Watchdog. You can see that at the time the thd command was executed the Watchdog was about to expire, within 1 second.

kev-dev /> thd
   9 classes loaded.   44.7 KB
   1 JVM instances active.
Command/10.0.0.27:55691/flash/watchdogTest.jar         0.557   mem: 20.9K  pid: 36  stk: 0.3K  obj: 2.1K  cls: 12.4K
         0.150  1: main, java/lang/Thread, main, SLEEP
     Watchdog: 'Watchdog Test', WDT_REBOOT, remaining = 0.880s

Here is the code listing for the above test application.

package watchdogtest;
 
import com.integpg.system.JANOS;
import com.integpg.system.Watchdog;
 
/**
 * This application tests the watchdog. A watchdog will be registered with the operating system. It will be fed a few
 * times and then left to be triggered. When it gets triggered we should see the registered action get carried out.
 */
public class WatchdogTest {
 
    public static void main(String[] args) throws InterruptedException {
        // instantiate the watchdog and register it to reboot when it gets triggered
        Watchdog watchdog = new Watchdog("Watchdog Test");
        watchdog.setAction(Watchdog.WDT_REBOOT);
        watchdog.activate(60000);
        // log to the syslog so that we can see exactly when the operating system reboots
        JANOS.syslog("Watchdog Started");
 
        // sleep for 30 seconds and then feed the watchdog.
        Thread.sleep(30000);
        watchdog.refresh();
        JANOS.syslog("Watchdog fed");
 
        // sleep for longer than the watchdog duration.  This will allow the watchdog to get triggered.  We 
        // should see that the reboot occurs 60 seconds after the last time the watchdog was fed
        Thread.sleep(120000);
    }
 
}

And here is the associated log entries from the jniorsys.log. As expected the timing works out. The watchdog was started, 30 seconds later we log that it was fed and then 60 seconds later we get the Assertion indicating that the reboot sequence has been commenced. 15 seconds are given to applications and system processes for safe shutdown.

11/17/17 14:13:19.302, Watchdog Started
11/17/17 14:13:49.368, Watchdog fed
11/17/17 14:14:49.487, ** Assertion: Watchdog Test watchdog triggered reboot (Line 1139)
11/17/17 14:14:49.496, ** Terminating: System
11/17/17 14:15:05.937, ** Reboot on assertion: Watchdog Test watchdog triggered reboot (Line 1139)
11/17/17 14:15:05.945, -- JANOS 412 v1.6.3-rc2 initialized (POR: 58)
By | Updated On November 7, 2023 2:26 pm | No Comments | Categories: , ,


INTEG Process Group, inc. © 2023

Real-Time
Mon - Fri, 8am - 4pm EST
P: 724-933-9350
PureChat
Always Available
Contact Form
sales@integpg.com
support@integpg.com

@integpg
@jniordev
265