Mostrando las entradas con la etiqueta java. Mostrar todas las entradas
Mostrando las entradas con la etiqueta java. Mostrar todas las entradas

viernes, 6 de febrero de 2015

jconsole and VisualVM over ssh tunnel on EC2 for Tomcat 7 using JMX

Hi, today I will talk about how to do a tunnel using ssh in order to monitor Apache Tomcat 7 using JMX in four simple steps.

Let's suppose:

  • Your Apache Tomcat 7 server is installed on Amazon EC2 platform
  • You want to monitor Tomcat from your Mac OS computer (or Linux) without having installed jconsole on EC2

Then, do the following.

1) On the EC2 server side assign the CATALINA_OPTS variable (and export it):

$CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

2) Restarts Apache Tomcat

3) Start the ssh tunnel:

ssh -D9999 -i your_keyfile.pem ec2-user@your_domain_name.com

4) On the client side, open a terminal and execute the following:

jconsole -J-DsocksProxyHost=localhost -J-DsocksProxyPort=9999 service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi

That's it!!

PS. Remember to adjust it according the ports you want
      For VisualVM, do not forget to configure the SOCKS proxy and pay attention to the option No Proxy Hosts in case of localhost



miércoles, 5 de marzo de 2008

Maximum subarray (java implementation)

You're given an array containing both positive and negative integers and required to find the subarray with the maximum sum.

This is an interesting problem, I read that the solution was given in 1977 in less than a minute, so I took the original algorithm for the article and I implemented with Java, enjoy it!

    public static void main(String[] args)
    {
        int[] offset = new int[2];
        int[] x = { 31, -41, 59, 26, -53, 58, 97, -93, -23, 18 };
        int n = x.length;
        int maxsofar = 0;
        for (int i = 0; i < n; i++)
            for (int j = i; j < n; j++)
            {
                int sum = 0;
                for (int k = i; k <= j; k++)
                    sum += x[k];
                /* sum is sum of x[i..j] */
                if (sum > maxsofar)
                {
                    offset[0] = i;
                    offset[1] = j;
                    maxsofar = sum;
                }
            }
        System.out.println("Subarray [" + offset[0] + "..." + offset[1]
                + "] = " + maxsofar);
    }