For example, we can enable java remote debug by adding following to command line.
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
But my application is running in yarn, I'm not sure which port is available.
So I want enable java debug in my code.
First I detect a available port and log in my program, then I can use this port to debug my application.
The address property specifies host (optionally) and port (only the port if host is left out). So address=5005 specifies the port 5005 in your case. If you want your program to wait until you connect your debugger, switch suspend=n to suspend=y.
Edit:
Maybe I misunderstood your question. In case you want to enable debugging programmatically, this won't be possible as the debugging facility JPDA is not exposing a Java API nor any other way to start and stop it programmatically.
I'm not sure this can be done from code; however according to an answer to this old question, it is possible to enable debugging for an already-running JVM using jsadebugd
As mentioned in said answer, the feature is marked experimental and unsupported so your mileage may vary.
Related
I am attempting to debug a remote Java application in a Linux environment with an argument. However, I can only find the option to define an argument when debugging a [local] Java application. The argument I am trying to define is java -Dsun.awt.disablegrab=true to avoid having the system hang when I debug in event handlers. Given the nature of this application, I cannot launch it locally; I can only debug it as a remote Java application and define the host as localhost. Is there a way to launch debug for a remote Java application with the aforementioned argument?
Thanks to everyone in advance!
In order to allow opening the port for remote debugging, the application (or its server)'s launch will be parametrized with Java command-line arguments already, e.g. something in the lines of:
-Djava.compiler=NONE -Xdebug -Xnoagent
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=[your desired port]
I would simply add your desired parameter to the list, when you launch the process in debug mode.
Where to find the launch configuration will depend on the type of application you're running.
Since you likely already know the port to connect to, you may want to grep it in your configuration files, in the targeted machine (i.e. in your local machine, in this specific case) - that might give you an idea what resource you need to make changes to.
Clarification
The idea here is that your local Eclipse is not launching the application when remote-debugging, it only connects to a socket of your own definition, with an open port to connect to your target machine.
Therefore, it it up to your application's launch configuration (i.e. how the java process is parametrized when launching your application) to define the socket for remote debugging if so required, and any launch parameters you may want.
I am attempting to configure an application for remote debugging. I am attempting to use the instructions under https://wrapper.tanukisoftware.com/doc/english/qna-eclipse-remote.html and have added the following lines to my wrapper.conf
wrapper.java.additional.16=-Xdebug
wrapper.java.additional.17=-Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y
When I start my application using console console the application does not freeze with the following:
Listening for transport dt_socket at address: 8001
instead it carries on running and I cannot connect to it. Can anyone advise what settings I may be missing in order to allow the application to be remotely debugged.
One of the earlier configuration number was commented out
#wrapper.java.additional.13
This appears to mean that 14,15,16,17 were also ignored. I re-numbered these and can now debug.
VisualVM/VisualGC provides quite a lot of useful GC-related metrics in real-time, but I want a command-line tool that can connect to a remote application via jstatd and record in CSV or XML ideally exactly the same metrics as VisualGC provides. It shouldn't be a problem to write my own, but from the first look I cannot find what protocol visualvm/jstatd use.
As I understand VisualGC is not open source: https://stackoverflow.com/questions/11096466/where-is-the-source-code-repository-for-visualgc, but are there any alternative open source tools? Are there any clues how about the protocol used?
I managed to connect to jstatd via RMI (default port 1099, JStatRemoteHost is the rmi-name), can attach to a particular VM - but http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/sun/jvmstat/monitor/remote/RemoteVm.java#RemoteVm is rather a very low-level interface with jstatd.
I've checked out the VisualVM source code from https://svn.java.net/svn/visualvm~svn/trunk
and just started looking at the 5mb codebase, however it doesn't use neither RemoteHost nor RemoteVm RMI-classes.
Thanks.
First I looked at the source code of VisualVM (~5mb), created a command-line tool that registers JvmstatModelProvider on JvmstatModelFactory, gets an Application, creates JvmJvmstatModel and extracts all MonitoredValues - it connects to a remote application via jstatd and prints changed values in format timeMillis,name,value
1369270235646,sun.gc.generation.2.space.0.capacity,16777216
1369270236666,sun.os.hrt.ticks,2511500491
1369270237581,sun.gc.generation.0.space.0.used,641408
1369270237582,sun.os.hrt.ticks,2512502544
One hour later I found the right command-line tool for my task https://code.google.com/p/hatter-source-code/wiki/hotstat, that doesn't use jstatd - but fine, I can still run it remotely via ssh.
I'm working with a certain external server product which happens to be proprietary. However, I do have the ability to modify the server's startup scripts. What I'd like to do is essentially set debugging breakpoints in the custom module code which I'm writing so as to be able to fix a bug I'm experiencing in my code.
Is there a way to do this, integrating Eclipse with debugging an external process?
If that certain external server product is a Java server, you should be able to debug your code running in it through standard Java remote debugging.
In Eclipse, open the Debug configurations and add a new configuraion of type "Remote Java Application", and enter the hostname of the server and the port the remote debugger listens to.
In the server startup script, you may need to add an additional Java option to enable remote debugging for the JVM and specify the port. Something like this (excerpt from the JBoss startup config file):
# Sample JPDA settings for remote socket debugging
JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
(address - 8787 in this case - is the port to connect to)
I'm trying to enable remote monitoring by using jmxremote. When i set the options in a '.bat' file, things are ok (i can connect to the process using JConsole), but fail to do so when i try to do that when the process is ran as a service, although i use the exact properties that i use when the process runs as a '.bat' file (e.g. -Dcom.sun.management.jmxremote etc.) can you please let me know what am i missing?
(Please note, the behavior is with and withouth password/access files, with 'authenticate' and 'password' set to true and false).
Thanks
Guy
If you specify only com.sun.management.jmxremote then the connection will only work as long as the process to be monitored and the monitoring tool run under the same user.
Since services usually run under a system account that's not the case.
You will need to specify a port to listen on to enable connections from other users: use com.sun.management.jmxremote. port for this.