我正在使用JConsole访问正在运行的MBean.
MBean使用自定义Jaas登录模块,并使用以下命令运行:
java -classpath UserLGUGroupHandlingApplication.jar;MBeanSecure.jar
-com.sun.management.jmxremote.login.config=management.properties
-Djava.security.auth.login.config=./sample_jaas.config
com.test.running.RunningImplementation
Run Code Online (Sandbox Code Playgroud)
management.properties文件看起来像这样:
com.sun.management.jmxremote.access.file=jmxremote.access
com.sun.management.jmxremote=true
com.sun.management.jmxremote.authenticate=true
com.sun.management.jmxremote.port=1234
com.sun.management.jmxremote.login.config=Sample
com.sun.management.jmxremote.ssl=false
com.sun.management.jmxremote.ssl.need.client.auth=false
Run Code Online (Sandbox Code Playgroud)
和sample_jaas.config:
Sample {
test.module.AETTLoginModule required debug=true;
};
Run Code Online (Sandbox Code Playgroud)
然后,用户将通过命令行中的JConsole登录来访问此运行进程.
jconsole -debug //or just jconsole
Run Code Online (Sandbox Code Playgroud)
用户选择"远程连接",使用RemoteProcess'localhost:1234'
loginmodule根据当前登录到Windows的用户处理用户验证和主体设置,用于查询单独的授权逻辑以确定访问级别.
我想要发生什么:
问题:
要在jconsole窗口中访问jmx进程,我必须输入一个虚拟用户名和密码,例如U:a,P:a,否则我收到以下错误:
java.lang.SecurityException: Authentication failed! Credentials required
at com.sun.jmx.remote.security.JMXPluggableAuthenticator.authenticationFailure(JMXPluggableAuthenticator.java:193)
at com.sun.jmx.remote.security.JMXPluggableAuthenticator.authenticate(JMXPluggableAuthenticator.java:145)
at sun.management.jmxremote.ConnectorBootstrap$AccessFileCheckerAuthenticator.authenticate(ConnectorBootstrap.java:201)
at javax.management.remote.rmi.RMIServerImpl.doNewClient(RMIServerImpl.java:213)
at javax.management.remote.rmi.RMIServerImpl.newClient(RMIServerImpl.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535) …Run Code Online (Sandbox Code Playgroud) 我有一个简单的JMX应用程序,它基于本教程公开了MBean
是否可以在扩展JCONSOLE的类路径中使用自定义类启动此应用程序,以便当客户端尝试远程访问它时,扩展的jconsole窗口会打开?
例如,我创建了一个简单的应用程序并将其打包在MyApp.jar中.然后我在cmd中使用以下命令运行它:
java -classpath JconsoleExtension.jar;MyApp.jar
-com.sun.management.jmxremote.login.config=management.properties
-Djava.security.auth.login.config=./sample_jaas.config
com.test.running.RunningImplementation
Run Code Online (Sandbox Code Playgroud)
使用managepement.properties看起来像这样:
com.sun.management.jmxremote=true
com.sun.management.jmxremote.port=1234
com.sun.management.jmxremote.login.config=Sample
Run Code Online (Sandbox Code Playgroud)
客户端是否可以使用以下方式远程连接:
jconsole hostname:1234
Run Code Online (Sandbox Code Playgroud)
并使用扩展功能拉出jconsole窗口?
或者,客户端在尝试连接时是否必须引用扩展名,例如:
jconsole hostname:1234 -classpath JconsoleExtension.jar
Run Code Online (Sandbox Code Playgroud) 我最近一直在审查代码,注意到在for循环中使用了这种语法
for(int i = 0, len = myArray.length; i < len; i++){
//some code
}
Run Code Online (Sandbox Code Playgroud)
而不是:
for(int i = 0; i < myArray.length; i++){
//some code
}
Run Code Online (Sandbox Code Playgroud)
理由是它更有效率,因为您不必继续使用每个循环查找myArray.length属性.
我创建了一个测试来检查是否是这种情况,并且在我的所有测试中,第一个for循环方法显着(大约70%)比第二个快.
我很好奇为什么这个语法没有被广泛采用,我认为这是一种更好的方法来使用for循环通过数组.
我一直在审查一些代码,我发现了以下字段:
private List<String> listOfStrings = java.util.ArrayList<String>();
Run Code Online (Sandbox Code Playgroud)
什么时候最好使用此代码而不是:
import java.util.ArrayList;
...
private List<String> listOfStrings = new ArrayList<String>();
Run Code Online (Sandbox Code Playgroud)
除了语法上的不同,还有什么好处吗?