We have two logs in project, one is standard output using: java project.jar > output.log; the other is logback configured in the logback.groovy.
And when I use kill -3 to capture the thread dump info, they went to the output.log.
Any way to output these info to the logback ?
And if I add the param -verbose:gc, how to output to the logback as well?
Thanks:)
As far as I'm aware, you cannot capture this information within the Java application. In both cases, the output comes from the JVM native code libraries and doesn't go through the Java IO libraries.
Related
I am starting a Spring Boot application in Windows using winsw and after it crashes I can't find the Java core dump file anywhere.
Where will the Java core dump file be located?
Thx.
The question of where Java core dumps are located on Windows gets a little complicated. The commonest answers are:
$JAVA_HOME/bin
The current working directory of the process
The file is typically named hs_err_<PID>.
However, rather than guessing you can tell Java where to write a dump file.
The default JVM argument for this, in Oracle JVMs, is: -XX:HeapDumpPath. For example:
-XX:HeapDumpPath=/path/to/dumps/directory/java_pid<pid>.hprof`
IBM provides its own flavour: -Xdump. For example
-Xdump:heap:label=/path/to/dumps/directory/heapdump.%Y%m%d.%H%M%S.%pid.%seq.dump
-Xdump:java:label=/path/to/dumps/directory/core.%Y%m%d.%H%M%S.%pid.%seq.dump
And if you run with -Xdump:what then a log event will be written to STDOUT on startup showing your the various dump parameters you have chosen.
I would like to automatically create a thread dump as part of a log collection script I have written.
I know that it is possible to generate a thread dump using jstack or kill -3 . The customer running the log collection script will only have a JRE installed so jstack is not an option.
If I use jstack and the pid of the JVM that the install4j launcher creates I get the thread dump...however invoking kill -3 with the same pid generates no output. I am currently directing both stderror and stdout to files using the install4j launcher configuration.
This is a linux launcher that is configured with the service option.
FWIW...I have tried not directing the output and also running my application as a console program instead of a service and none of these allow 'kill -3' to work.
I'm using install4j 6.0
Lastly, I do not want to use -XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=dump.log because of the unknown overhead it might create.
Any help would be appreciated!
I would suggest to use the ThreadMXBean to get this information programmatically in the same process rather than use signal handlers from another process. The API documentation is at
http://docs.oracle.com/javase/8/docs/api/java/lang/management/ThreadMXBean.html
Here's a full example of how to use this MBean.
In that way you can write the information explicitly to wherever you want it to go.
I have a Java process. I am using log4j for logging purpose. I have specified in log4j.xml, location and name of log file. logging is working fine. I have problem with kill -3 logs here.
I trying to get process-dump using kill -QUIT <pid>/ killl -3 <pid>. I expected the dump generated by kill -3 to get updated in log file specified in log4j.xml.
But it is not happening that way. I need the dump to observer thread statuses. I do not know any other way to get process dump of a running process.
kill -3 should output to stdout, so it should be wherever your stdout goes. If not you could try playing with -XX:LogFile JVM option.
Alternative way is jstack as suggested by NPE.
Another alternative is to use jvisualvm - it will produce stackdump in its nice GUI and you can copy it from there.
I need the dump to observer thread statuses. I do not know any other way to get process dump of a running process.
You can use jstack for this.
I understand there's -Xloggc option exists for outputting GC output to separate file. But it doesn't work for me. I've 16 java processes with same main running on one machine so I can't really hardcode file path. Ideally I want to specify only directory where separate pid specific files are created. Is that possible? Note I don't want GC output mixed with stdout and hence a need for separate file.
Version : SunJDK 1.5_13
Can you change the loggc directory with
-Xloggc:/path/`date +%Y%M%d%H%m%S`.gc.log
Couldn't you mix standard out and GC and then grep out what you want? There should be much coming out of standard out, or at least not much that you couldn't redirect elsewhere if you are using a logging framework.
When I issue a kill -3 <pid> command to my Java program, it generates the thread dump on the console. How do I redirect this to a file?
Two options:
Run your Java application with stdout redirected
java com.example.MyApp > out.txt
Use jstack instead.
The jstack utility allows you to get a thread dump and send the output to the current console instead of the stdout of the Java application, allowing you to redirect it.
For example, if the PID of your Java application is 12345 (use the jps utility to find it quickly):
jstack 12345 > threads.txt
I usually use the NetBeans profiler, but jvisualvm is available from the command line.
If you want details of all threads and other JVM details, try jconsole.
Please append following JVM arguments to your application. Thread dump should be captured at dump.log.
-XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=dump.log
Please note it does not redirect, but enables JVM diagnostic logging. So, there could be possible over head as well.
However, if you can have JDK in the environment, using jstack or jcmd (jcmd is preferred with JDK 1.8), you can capture thread dump and redirect to a file.
you can generate java thread dumps using 4 ways excluding the kill -QUIT way.