JAVA-2111: Split or move core-java-jvm module (#9688)
* JAVA-2111: Moved boolean Memory Layout article * JAVA-2111: Moved Shutdown Hooks article * JAVA-2111: Updated README files * JAVA-2111: Fixed prev link
This commit is contained in:
@@ -11,8 +11,7 @@ This module contains articles about working with the Java Virtual Machine (JVM).
|
||||
- [A Guide to System.exit()](https://www.baeldung.com/java-system-exit)
|
||||
- [Guide to System.gc()](https://www.baeldung.com/java-system-gc)
|
||||
- [Runtime.getRuntime().halt() vs System.exit() in Java](https://www.baeldung.com/java-runtime-halt-vs-system-exit)
|
||||
- [Adding Shutdown Hooks for JVM Applications](https://www.baeldung.com/jvm-shutdown-hooks)
|
||||
- [How to Get the Size of an Object in Java](http://www.baeldung.com/java-size-of-object)
|
||||
- [What Causes java.lang.OutOfMemoryError: unable to create new native thread](https://www.baeldung.com/java-outofmemoryerror-unable-to-create-new-native-thread)
|
||||
- [View Bytecode of a Class File in Java](https://www.baeldung.com/java-class-view-bytecode)
|
||||
- [boolean and boolean[] Memory Layout in the JVM](https://www.baeldung.com/jvm-boolean-memory-layout)
|
||||
- More articles: [[next -->]](/core-java-modules/core-java-jvm-2)
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.baeldung.boolsize;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openjdk.jol.info.ClassLayout;
|
||||
import org.openjdk.jol.vm.VM;
|
||||
|
||||
public class BooleanSizeUnitTest {
|
||||
|
||||
@Test
|
||||
public void printingTheVMDetails() {
|
||||
System.out.println(VM.current().details());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void printingTheBoolWrapper() {
|
||||
System.out.println(ClassLayout.parseClass(BooleanWrapper.class).toPrintable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void printingTheBoolArray() {
|
||||
boolean[] value = new boolean[3];
|
||||
|
||||
System.out.println(ClassLayout.parseInstance(value).toPrintable());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.baeldung.boolsize;
|
||||
|
||||
class BooleanWrapper {
|
||||
private boolean value;
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package com.baeldung.shutdownhook;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
public class ShutdownHookUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenAHook_WhenShutsDown_ThenHookShouldBeExecuted() {
|
||||
Thread printingHook = new Thread(() -> System.out.println("In the middle of a shutdown"));
|
||||
Runtime.getRuntime().addShutdownHook(printingHook);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addingAHook_WhenThreadAlreadyStarted_ThenThrowsAnException() {
|
||||
Thread longRunningHook = new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(300);
|
||||
} catch (InterruptedException ignored) {}
|
||||
});
|
||||
longRunningHook.start();
|
||||
|
||||
assertThatThrownBy(() -> Runtime.getRuntime().addShutdownHook(longRunningHook))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Hook already running");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addingAHook_WhenAlreadyExists_ThenAnExceptionWouldBeThrown() {
|
||||
Thread unfortunateHook = new Thread(() -> {});
|
||||
Runtime.getRuntime().addShutdownHook(unfortunateHook);
|
||||
|
||||
assertThatThrownBy(() -> Runtime.getRuntime().addShutdownHook(unfortunateHook))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Hook previously registered");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeAHook_WhenItIsAlreadyRegistered_ThenWouldDeRegisterTheHook() {
|
||||
Thread willNotRun = new Thread(() -> System.out.println("Won't run!"));
|
||||
Runtime.getRuntime().addShutdownHook(willNotRun);
|
||||
|
||||
assertThat(Runtime.getRuntime().removeShutdownHook(willNotRun)).isTrue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user