add maven as package manager

add ShowObjectHeader.java to show object header
This commit is contained in:
2025-02-19 13:21:49 +08:00
parent 103b75b80b
commit 2a2707c4e7
20 changed files with 146 additions and 19 deletions

14
.idea/compiler.xml generated Normal file
View 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>

View 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
View 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
View File

@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <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"> <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>

View File

@ -1,11 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4"> <module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="AdditionalModuleElements">
<exclude-output /> <content url="file://$MODULE_DIR$" dumb="true">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content> </content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

38
pom.xml Normal file
View 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>

View File

@ -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 * use javap -v ObjectCreate.class or javap -c ObjectCreate.class to see byte code
*/ */
public class ObjectCreate { public class ObjectCreate {

View 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());
}
}

View File

@ -1,4 +1,4 @@
package createthread; package main.java.jvm.createthread;
public class CreateByAnonymousClass { public class CreateByAnonymousClass {

View File

@ -1,4 +1,4 @@
package createthread; package main.java.jvm.createthread;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask; import java.util.concurrent.FutureTask;

View File

@ -1,4 +1,4 @@
package createthread; package main.java.jvm.createthread;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;

View File

@ -1,4 +1,4 @@
package createthread; package main.java.jvm.createthread;
import java.util.concurrent.*; import java.util.concurrent.*;

View File

@ -1,4 +1,4 @@
package createthread; package main.java.jvm.createthread;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;

View File

@ -1,4 +1,4 @@
package createthread; package main.java.jvm.createthread;
import java.util.concurrent.FutureTask; import java.util.concurrent.FutureTask;

View File

@ -1,4 +1,4 @@
package createthread; package main.java.jvm.createthread;
public class CreateByRunnable implements Runnable{ public class CreateByRunnable implements Runnable{
@Override @Override

View File

@ -1,4 +1,4 @@
package createthread; package main.java.jvm.createthread;
public class CreateByThread extends Thread{ public class CreateByThread extends Thread{
@Override @Override

View File

@ -1,4 +1,4 @@
package createthread; package main.java.jvm.createthread;
public class CreateByThreadGroup { public class CreateByThreadGroup {

View File

@ -1,4 +1,4 @@
package createthread; package main.java.jvm.createthread;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;

View File

@ -1,4 +1,4 @@
package recursive; package main.java.recursive;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -1,4 +1,4 @@
package recursive; package main.java.recursive;
import java.util.*; import java.util.*;