Skip to content

Commit

Permalink
feat: 统一 pom
Browse files Browse the repository at this point in the history
  • Loading branch information
dunwu committed Jul 17, 2024
1 parent 2ccb61b commit de6e74c
Show file tree
Hide file tree
Showing 16 changed files with 319 additions and 122 deletions.
30 changes: 14 additions & 16 deletions codes/javacore-advanced/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
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>io.github.dunwu.javacore</groupId>
<parent>
<groupId>io.github.dunwu.javacore</groupId>
<artifactId>javacore</artifactId>
<version>1.0.1</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>javacore-advanced</artifactId>
<version>1.0.1</version>
<name>JavaCore :: Advanced</name>

<properties>
Expand Down Expand Up @@ -45,26 +50,19 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.junit.platform</groupId>-->
<!-- <artifactId>junit-platform-launcher</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.github.dunwu</groupId>
<artifactId>dunwu-dependencies</artifactId>
<version>1.1.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
21 changes: 7 additions & 14 deletions codes/javacore-basics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
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>io.github.dunwu.javacore</groupId>
<parent>
<groupId>io.github.dunwu.javacore</groupId>
<artifactId>javacore</artifactId>
<version>1.0.1</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>javacore-basics</artifactId>
<version>1.0.1</version>
<name>JavaCore :: Basics</name>

<properties>
Expand Down Expand Up @@ -34,16 +39,4 @@
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.github.dunwu</groupId>
<artifactId>dunwu-dependencies</artifactId>
<version>1.0.6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@

public class VariableDemo {

// 类变量(静态变量
private static int v1 = 0;
// 静态变量
private static String v1 = "静态变量";

// 实例变量
private String v2 = "word";
// 成员变量
private String v2 = "成员变量";

public void method() {
public void test(String v4) {
// 局部变量
int v3 = 0;
String v3 = "局部变量";
System.out.println(v1);
System.out.println(v2);
System.out.println(v3);
System.out.println(v4);
}

public static void main(String[] args) {
VariableDemo demo = new VariableDemo();
demo.test("参数变量");
}

}
21 changes: 7 additions & 14 deletions codes/javacore-concurrent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
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>io.github.dunwu.javacore</groupId>
<parent>
<groupId>io.github.dunwu.javacore</groupId>
<artifactId>javacore</artifactId>
<version>1.0.1</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>javacore-concurrent</artifactId>
<version>1.0.1</version>
<name>JavaCore :: Concurrent</name>

<properties>
Expand Down Expand Up @@ -42,16 +47,4 @@
<artifactId>spring-core</artifactId>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.github.dunwu</groupId>
<artifactId>dunwu-dependencies</artifactId>
<version>1.0.6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package io.github.dunwu.javacore.concurrent.container;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
* BlockingQueue 示例
*
* @author <a href="mailto:[email protected]">Zhang Peng</a>
* @date 2024-07-15
*/
public class ArrayBlockingQueueDemo {

public static final String EXIT_MSG = "Good bye!";

public static void main(String[] args) {
// 使用较小的队列,以更好地在输出中展示其影响
BlockingQueue<String> queue = new ArrayBlockingQueue<>(3);
Producer producer = new Producer(queue);
Consumer consumer = new Consumer(queue);
new Thread(producer).start();
new Thread(consumer).start();
}

static class Producer implements Runnable {

private BlockingQueue<String> queue;

public Producer(BlockingQueue<String> q) {
this.queue = q;
}

@Override
public void run() {
for (int i = 0; i < 20; i++) {
try {
Thread.sleep(5L);
String msg = "Message" + i;
System.out.println("Produced new item: " + msg);
queue.put(msg);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

try {
System.out.println("Time to say good bye!");
queue.put(EXIT_MSG);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}

static class Consumer implements Runnable {

private BlockingQueue<String> queue;

public Consumer(BlockingQueue<String> q) {
this.queue = q;
}

@Override
public void run() {
try {
String msg;
while (!EXIT_MSG.equalsIgnoreCase((msg = queue.take()))) {
System.out.println("Consumed item: " + msg);
Thread.sleep(10L);
}
System.out.println("Got exit message, bye!");
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}

}
// 输出示例:
//
// Produced new item: Message0
// Consumed item: Message0
// Produced new item: Message1
// Consumed item: Message1
// Produced new item: Message2
// Produced new item: Message3
// Consumed item: Message2
// Produced new item: Message4
// Produced new item: Message5
// Consumed item: Message3
// Produced new item: Message6
// Produced new item: Message7
// Consumed item: Message4
// Produced new item: Message8
// Consumed item: Message5
// Produced new item: Message9
// Consumed item: Message6
// Produced new item: Message10
// Consumed item: Message7
// Produced new item: Message11
// Consumed item: Message8
// Produced new item: Message12
// Consumed item: Message9
// Produced new item: Message13
// Consumed item: Message10
// Produced new item: Message14
// Consumed item: Message11
// Produced new item: Message15
// Consumed item: Message12
// Produced new item: Message16
// Consumed item: Message13
// Produced new item: Message17
// Consumed item: Message14
// Produced new item: Message18
// Consumed item: Message15
// Produced new item: Message19
// Consumed item: Message16
// Time to say good bye!
// Consumed item: Message17
// Consumed item: Message18
// Consumed item: Message1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.github.dunwu.javacore.concurrent.forkjoin;

import java.util.concurrent.CompletableFuture;

/**
* @author <a href="mailto:[email protected]">Zhang Peng</a>
* @date 2024-02-21
*/
public class CompletableFutureDemo02 {

public static void main(String[] args) {
noException();
catchException();
catchException2();
}

public static void noException() {
try {
CompletableFuture.runAsync(() -> {
int num = 1 / 0;
});
} catch (Exception e) {
System.err.println("noException: " + e.getMessage());
}
}

public static void catchException() {
try {
CompletableFuture.runAsync(() -> {
int num = 1 / 0;
}).get();
} catch (Exception e) {
System.err.println("catchException: " + e.getMessage());
}
}

public static void catchException2() {
try {
CompletableFuture.runAsync(() -> {
int num = 1 / 0;
}).join();
} catch (Exception e) {
System.err.println("catchException2: " + e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.github.dunwu.javacore.concurrent.sync;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class VolatileDemo {

public volatile static int count = 0;

public void add() {
count++;
}

public static void main(String[] args) throws InterruptedException {
ExecutorService threadPool = Executors.newFixedThreadPool(5);
VolatileDemo volatileAtomicityDemo = new VolatileDemo();
for (int i = 0; i < 5; i++) {
threadPool.execute(() -> {
for (int j = 0; j < 500; j++) {
volatileAtomicityDemo.add();
}
});
}
// 等待 1.5 秒,保证上面程序执行完成
Thread.sleep(1500);
System.out.println(count);
threadPool.shutdown();
}

}
21 changes: 7 additions & 14 deletions codes/javacore-container/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
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>io.github.dunwu.javacore</groupId>
<parent>
<groupId>io.github.dunwu.javacore</groupId>
<artifactId>javacore</artifactId>
<version>1.0.1</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>javacore-container</artifactId>
<version>1.0.1</version>
<name>JavaCore :: Container</name>
<description>Java 容器使用示例</description>

Expand Down Expand Up @@ -35,16 +40,4 @@
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.github.dunwu</groupId>
<artifactId>dunwu-dependencies</artifactId>
<version>1.0.6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @since 2020-08-11
*/
@Slf4j
public class AsList示例 {
public class ArraysAsListDemo {

public static void main(String[] args) {
System.out.println("====================== wrong1 ======================");
Expand Down
Loading

0 comments on commit de6e74c

Please sign in to comment.