Skip to content

Instantly share code, notes, and snippets.

View cleantutorials's full-sized avatar

Clean Tutorials cleantutorials

View GitHub Profile
@cleantutorials
cleantutorials / RemoteJavaProcess.java
Created May 19, 2020 04:33
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);
}
}
@cleantutorials
cleantutorials / RegisterMyMBean.java
Created May 19, 2020 04:25
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;
@cleantutorials
cleantutorials / JMXTutorialMBean.java
Created May 19, 2020 04:24
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
package com.cleantutorials.jconsole.jmx;
public class JMXTutorial implements JMXTutorialMBean {
private int noOfStudents;
public int getNoOfStudents() {
return noOfStudents;
}
public void setNoOfStudents(int noOfStudents) {
@cleantutorials
cleantutorials / deadlock_stacktrace.txt
Created January 4, 2020 21:23
Stack trace of simple deadlock example using Jstack tool.
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)
@cleantutorials
cleantutorials / StackTraceExample.java
Created January 4, 2020 21:17
An example program to demonstrate what a stack trace looks like. The stack trace for the main thread is in the comments.
public class StackTraceExample {
public static void main(String[] args) {
StackTraceExample example = new StackTraceExample();
example.method1();
}
public void method1() {
method2();
}
@cleantutorials
cleantutorials / heapdump_command.txt
Created November 20, 2019 21:20
Command to take Heap dump of Java Application using Jmap
jmap -dump:live,file=<file-name + .hprof> <pid>
@cleantutorials
cleantutorials / Dog.java
Last active September 1, 2019 04:21
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.
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;