Skip to content

Instantly share code, notes, and snippets.

Avatar

Clean Tutorials cleantutorials

View GitHub Profile
@cleantutorials
cleantutorials / Dog.java
Last active Sep 1, 2019
The Dog POJO representing a Dog. The class has a faulty logic in the equals method which can lead to memory leaks if the object is used as key in Sets/Maps.
View Dog.java
package com.cleantutorials.jconsole.memory;
/**
* Dog represents a dog which can be uniquely identified by the MicroChip ID and
* can optionally have a name.
*/
public class Dog {
/** The Unique MicroChip ID of the dog. */
private int microChipID;
@cleantutorials
cleantutorials / heapdump_command.txt
Created Nov 20, 2019
Command to take Heap dump of Java Application using Jmap
View heapdump_command.txt
jmap -dump:live,file=<file-name + .hprof> <pid>
@cleantutorials
cleantutorials / StackTraceExample.java
Created Jan 4, 2020
An example program to demonstrate what a stack trace looks like. The stack trace for the main thread is in the comments.
View StackTraceExample.java
public class StackTraceExample {
public static void main(String[] args) {
StackTraceExample example = new StackTraceExample();
example.method1();
}
public void method1() {
method2();
}
@cleantutorials
cleantutorials / deadlock_stacktrace.txt
Created Jan 4, 2020
Stack trace of simple deadlock example using Jstack tool.
View deadlock_stacktrace.txt
Github Link: https://github.com/cleantutorials/JConsole/blob/master/src/main/java/com/cleantutorials/jconsole/thread/DeadlockExample.java
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.221-b11 mixed mode):
"DestroyJavaVM" #13 prio=5 os_prio=0 tid=0x0000000002402800 nid=0x31a8 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Thread-1" #12 prio=5 os_prio=0 tid=0x000000001d841800 nid=0x7ef4 waiting for monitor entry [0x000000001f5af000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.cleantutorials.jconsole.thread.DeadlockExample$2.run(DeadlockExample.java:40)
View JMXTutorial.java
package com.cleantutorials.jconsole.jmx;
public class JMXTutorial implements JMXTutorialMBean {
private int noOfStudents;
public int getNoOfStudents() {
return noOfStudents;
}
public void setNoOfStudents(int noOfStudents) {
View JMXTutorialMBean.java
package com.cleantutorials.jconsole.jmx;
public interface JMXTutorialMBean {
public int getNoOfStudents(); // Reading the value of the attribute (Getter method)
public void setNoOfStudents(int x); // Writing the value of the attribute (Setter Method)
public void incrementNoOfStudents(); // Any operation
View RegisterMyMBean.java
package com.cleantutorials.jconsole.jmx;
import java.lang.management.ManagementFactory;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
View RemoteJavaProcess.java
package com.cleantutorials.jconsole.jmx;
public class RemoteJavaProcess {
public static void main(String[] args) throws InterruptedException {
System.out.println("Ready for incomming connections from JConsole.");
Thread.sleep(600000);
}
}