Jconsle

1. jconsole 远程连接:

    JConsole很好用,可以解决很多疑难杂症。但远程连接需要设置一下Java opt才可以使用。以下是步骤:

    1). 在java opt下添加如下内容:

         如果是无须验证添加

        # 指定远程服务的端口

        JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=12345"          

        # 指定远程服务的认证

        JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false"  
        JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false"

   2). 如无须验证,服务就设置完成了。

        如需密码验证

        a. 执行脚本中添加如下内容:

        JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=12345"
        JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=true"
        JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false"
        JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.pwd.file=/usr/java/jdk1.6.0_02/jre/lib/management/jmxremote.password"

        b. 将/usr/java/jdk1.6.0_02/jre/lib/management下的jmxremote.password.template,拷贝一份叫jmxremote.password。进去将内容全部删去,添加一行

            controlRole   R&D    (用户名,密码)

        c. 将jmxremote.password和jmxremote.access改成600权限,和所属该程序用户

           chown jboss:jboss jmxremote.access  jmxremote.password

           chmod 600 jmxremote.access  jmxremote.password

       d. 之后在JConsole里添加用户名,密码就可以了。

       注:如果JConsole不能访问本机的程序的话,在java opt里添加如下内容:

            -Dcom.sun.management.jmxremote

  转自:http://java-boy.iteye.com/blog/608438

 

 tomcat 配置中一般讲上诉内容放到:

JAVA 程序测试,测试类:

package push;
/**
 * @author tianlin
 * 2015年12月5日 下午3:14:46
 *
 **/
public class JconsoleTest {
	
	public static void main(String[] args) throws InterruptedException {
		
		MyThread t1 = new MyThread();
		t1.start();
		MyThread t2 = new MyThread();
		t2.start();
		MyThread t3 = new MyThread();
		t3.start();
		MyThread t4 = new MyThread();
		t4.start();
	}

}

class MyThread extends Thread {
	
	@Override
	public void run() {
		
		boolean flag = true;
		while(flag){
			for(int i=0;i<600;i++){
				if(i==100){
					flag = false;
				}
				try {
					Thread.sleep(10000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("------------------------------" + i);
			}
		}
		
	}
}

     linux 编写执行脚本start.sh,内容如下:

java -Dcom.sun.management.jmxremote.port=8880 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=192.168.1.210  -Dcom.sun.management.jmxremote.ssl=false push/JconsoleTest

     备注:-Djava.rmi.server.hostname=192.168.1.210  -Dcom.sun.management.jmxremote.ssl=false  貌似可以不写

 

原文地址:https://www.cnblogs.com/Jtianlin/p/5021540.html