How does the JVM terminate daemon threads? or How to write daemon threads that terminate gracefully

I just wrote the following code as a test: public class DaemonThreadPlay { public static void main(String [] args) { Thread daemonThread = new Thread() { public void run() { while (true) { try { System.out.println(“Try block executed”); Thread.sleep(1000l); } catch (Throwable t) { t.printStackTrace(); } } } @Override public void finalize() { System.out.println(“Finalize method … Read more

Duplicated Java runtime options : what is the order of preference?

As always, check your local JVM’s specific implementation but here is a quick way to check from the command line without having to code. > java -version; java -Xmx1G -XX:+PrintFlagsFinal -Xmx2G 2>/dev/null | grep MaxHeapSize java version “1.8.0_25” Java(TM) SE Runtime Environment (build 1.8.0_25-b17) Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode) uintx MaxHeapSize … Read more

Java: What is the difference between and ?

<init> is the (or one of the) constructor(s) for the instance, and non-static field initialization. <clinit> are the static initialization blocks for the class, and static field initialization. class X { static Log log = LogFactory.getLog(); // <clinit> private int x = 1; // <init> X(){ // <init> } static { // <clinit> } }

Why is there no GIL in the Java Virtual Machine? Why does Python need one so bad?

Python (the language) doesn’t need a GIL (which is why it can perfectly be implemented on JVM [Jython] and .NET [IronPython], and those implementations multithread freely). CPython (the popular implementation) has always used a GIL for ease of coding (esp. the coding of the garbage collection mechanisms) and of integration of non-thread-safe C-coded libraries (there … Read more

Garbage collection on intern’d strings, String Pool, and perm-space

String literals are interned. As of Java 7, the HotSpot JVM puts interned Strings in the heap, not permgen. Prior to java 7, hotspot put interned Strings in permgen. However, interned Strings in permgen were garbage collected. Apparently, Class objects in permgen are also collectable, so everything in permgen is collectable, though permgen collection might … Read more