Unofficial Content
  • This documentation is valid for:

This sample shows an interesting use of JMX to detect a loop; we used the Thread View of the SUN JConsole utility to detect a loop in a Java Web Application.


  • A Java Web application generated with GeneXus 9.0 or higher and JRE 1.5 or higher.
  • The Management model property enabled.
  • a JMX client, in this case we used jconsole, shipped with J2SE 5.0 or higher.


Suppose you did a refactoring on a Web Panel and by mistake you forgot to increment a variable associated to a loop in a subroutine executed within a loop, as shown below:

Event 'loop01'
    &max = 100
    Do While &i <= &max
        Do 'Something'        
Sub 'Something'
    If 1 = 2
        &i += 1

As you can see, the execution of this code will cause the application to hang up, because the "&i += 1" code is never executed as " 1 = 2 " is always false; this means that the main loop in the "loop01" event won't finish.

Using JMX or just the task manager, you will notice that as soon as this code is executed the CPU usage raises. In this situation you can use tools such as JMX to help you understand what is happening within the Java Virtual Machine.

To try to understand what was going on, we opened the JMX Jconsole and checked the thread view searching for some clue, for example some stack trace pointing to some GeneXus application class.

As the following picture shows, we were very lucky because we detected that the http-8080-Procesor17 thread was executing always the same lines of code in the loop01_impl class:

Using The Thread Tab In JConsole

Based on the line number detailed in the Java Stack Trace (in this case 466) we checked the java class generated code associated to the loop01 Web Panel and found the following:

public void e112A2( )
      /* 'loop01' Routine */
      AV6max = 100 ;
      while ( ( AV7i <= AV6max ) )
         /* Execute user subroutine: S112 */
         S112 ();
         if ( returnInSub ) // <<<<<------ This is the Line 466 in the GeneXus Generated Code !!!!!
            returnInSub = true;
            if (true) return;

Based on this information we could detect that there was a bug in the GeneXus code, the &i variable was never updated !!!!; we fixed and checked the correct execution of the code in the loop01 WebPanel.


Event though this is just a sample; notice that using JMX technology provides very useful information on several resources that can help you get a deeper understanding of how your applications run.

See Also



Last update: January 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant