add maven as package manager
add ShowObjectHeader.java to show object header
This commit is contained in:
14
.idea/compiler.xml
generated
Normal file
14
.idea/compiler.xml
generated
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="java_test" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel target="21" />
|
||||
</component>
|
||||
</project>
|
8
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
8
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,java.lang.foreign.Arena,ofAuto,java.lang.foreign.Arena,global,java.util.concurrent.Executors,newFixedThreadPool" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
20
.idea/jarRepositories.xml
generated
Normal file
20
.idea/jarRepositories.xml
generated
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://maven.aliyun.com/repository/central" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
8
.idea/misc.xml
generated
8
.idea/misc.xml
generated
@ -1,5 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
|
@ -1,11 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<component name="AdditionalModuleElements">
|
||||
<content url="file://$MODULE_DIR$" dumb="true">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
38
pom.xml
Normal file
38
pom.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.kuaslab</groupId>
|
||||
<artifactId>java-learning</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jol</groupId>
|
||||
<artifactId>jol-core</artifactId>
|
||||
<version>0.17</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>{maven.compiler.source}</source>
|
||||
<target>{maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -1,7 +1,7 @@
|
||||
package jvm;
|
||||
package main.java.jvm;
|
||||
|
||||
/**
|
||||
* This class is intended to demo how jvm create object and invoke constructor. Please see byte code.
|
||||
* This class is intended to demo how main.java.jvm create object and invoke constructor. Please see byte code.
|
||||
* use javap -v ObjectCreate.class or javap -c ObjectCreate.class to see byte code
|
||||
*/
|
||||
public class ObjectCreate {
|
42
src/main/java/jvm/ShowObjectHeader.java
Normal file
42
src/main/java/jvm/ShowObjectHeader.java
Normal file
@ -0,0 +1,42 @@
|
||||
package jvm;
|
||||
|
||||
import org.openjdk.jol.info.ClassLayout;
|
||||
|
||||
public class ShowObjectHeader {
|
||||
|
||||
static final Object lock = new Object();
|
||||
|
||||
public void syncObject() {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
System.out.println("enter sync");
|
||||
System.out.println(ClassLayout.parseInstance(lock).toPrintable());
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
ShowObjectHeader showObjectHeader = new ShowObjectHeader();
|
||||
System.out.println("newly created");
|
||||
System.out.println(ClassLayout.parseInstance(lock).toPrintable());
|
||||
|
||||
Thread t1 = new Thread(showObjectHeader::syncObject);
|
||||
t1.start();
|
||||
t1.join();
|
||||
|
||||
Thread t2 = new Thread(showObjectHeader::syncObject);
|
||||
Thread t3 = new Thread(showObjectHeader::syncObject);
|
||||
|
||||
t2.start();
|
||||
t3.start();
|
||||
|
||||
t2.join();
|
||||
t3.join();
|
||||
System.out.println("after sync");
|
||||
System.out.println(ClassLayout.parseInstance(lock).toPrintable());
|
||||
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package createthread;
|
||||
package main.java.jvm.createthread;
|
||||
|
||||
public class CreateByAnonymousClass {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package createthread;
|
||||
package main.java.jvm.createthread;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.FutureTask;
|
@ -1,4 +1,4 @@
|
||||
package createthread;
|
||||
package main.java.jvm.createthread;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
@ -1,4 +1,4 @@
|
||||
package createthread;
|
||||
package main.java.jvm.createthread;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package createthread;
|
||||
package main.java.jvm.createthread;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
@ -1,4 +1,4 @@
|
||||
package createthread;
|
||||
package main.java.jvm.createthread;
|
||||
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package createthread;
|
||||
package main.java.jvm.createthread;
|
||||
|
||||
public class CreateByRunnable implements Runnable{
|
||||
@Override
|
@ -1,4 +1,4 @@
|
||||
package createthread;
|
||||
package main.java.jvm.createthread;
|
||||
|
||||
public class CreateByThread extends Thread{
|
||||
@Override
|
@ -1,4 +1,4 @@
|
||||
package createthread;
|
||||
package main.java.jvm.createthread;
|
||||
|
||||
public class CreateByThreadGroup {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package createthread;
|
||||
package main.java.jvm.createthread;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
@ -1,4 +1,4 @@
|
||||
package recursive;
|
||||
package main.java.recursive;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
@ -1,4 +1,4 @@
|
||||
package recursive;
|
||||
package main.java.recursive;
|
||||
|
||||
import java.util.*;
|
||||
|
Reference in New Issue
Block a user