Split or move core-java-modules/core-java-concurrency-basic module (#7799)
This commit is contained in:
parent
dac59fbec2
commit
6073d2d451
10
core-java-modules/core-java-concurrency-basic-2/README.md
Normal file
10
core-java-modules/core-java-concurrency-basic-2/README.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
=========
|
||||||
|
|
||||||
|
## Core Java Concurrency Basic 2 Examples
|
||||||
|
|
||||||
|
### Relevant Articles:
|
||||||
|
- [How to Delay Code Execution in Java](https://www.baeldung.com/java-delay-code-execution)
|
||||||
|
- [wait and notify() Methods in Java](https://www.baeldung.com/java-wait-notify)
|
||||||
|
- [Difference Between Wait and Sleep in Java](https://www.baeldung.com/java-wait-and-sleep)
|
||||||
|
- [Guide to the Synchronized Keyword in Java](https://www.baeldung.com/java-synchronized)
|
||||||
|
- [Life Cycle of a Thread in Java](https://www.baeldung.com/java-thread-lifecycle)
|
33
core-java-modules/core-java-concurrency-basic-2/pom.xml
Normal file
33
core-java-modules/core-java-concurrency-basic-2/pom.xml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<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.baeldung</groupId>
|
||||||
|
<artifactId>core-java-concurrency-basic-2</artifactId>
|
||||||
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
|
<name>core-java-concurrency-basic-2</name>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<artifactId>parent-java</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../../parent-java</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>core-java-concurrency-basic-2</finalName>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||||
|
</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<logger name="org.springframework" level="WARN" />
|
||||||
|
<logger name="org.springframework.transaction" level="WARN" />
|
||||||
|
|
||||||
|
<!-- in order to debug some marshalling issues, this needs to be TRACE -->
|
||||||
|
<logger name="org.springframework.web.servlet.mvc" level="WARN" />
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
@ -1,15 +1,15 @@
|
|||||||
package com.baeldung.concurrent.waitandnotify;
|
package com.baeldung.concurrent.waitandnotify;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
|
||||||
import org.junit.After;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class NetworkIntegrationTest {
|
public class NetworkIntegrationTest {
|
||||||
|
|
@ -3,18 +3,13 @@
|
|||||||
## Core Java Concurrency Basic Examples
|
## Core Java Concurrency Basic Examples
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
- [Guide To CompletableFuture](http://www.baeldung.com/java-completablefuture)
|
- [Guide To CompletableFuture](https://www.baeldung.com/java-completablefuture)
|
||||||
- [A Guide to the Java ExecutorService](http://www.baeldung.com/java-executor-service-tutorial)
|
- [A Guide to the Java ExecutorService](https://www.baeldung.com/java-executor-service-tutorial)
|
||||||
- [Guide to java.util.concurrent.Future](http://www.baeldung.com/java-future)
|
- [Guide to java.util.concurrent.Future](https://www.baeldung.com/java-future)
|
||||||
- [Difference Between Wait and Sleep in Java](http://www.baeldung.com/java-wait-and-sleep)
|
- [Overview of the java.util.concurrent](https://www.baeldung.com/java-util-concurrent)
|
||||||
- [Guide to the Synchronized Keyword in Java](http://www.baeldung.com/java-synchronized)
|
- [Implementing a Runnable vs Extending a Thread](https://www.baeldung.com/java-runnable-vs-extending-thread)
|
||||||
- [Overview of the java.util.concurrent](http://www.baeldung.com/java-util-concurrent)
|
- [How to Kill a Java Thread](https://www.baeldung.com/java-thread-stop)
|
||||||
- [Implementing a Runnable vs Extending a Thread](http://www.baeldung.com/java-runnable-vs-extending-thread)
|
- [ExecutorService – Waiting for Threads to Finish](https://www.baeldung.com/java-executor-wait-for-threads)
|
||||||
- [How to Kill a Java Thread](http://www.baeldung.com/java-thread-stop)
|
- [Runnable vs. Callable in Java](https://www.baeldung.com/java-runnable-callable)
|
||||||
- [ExecutorService – Waiting for Threads to Finish](http://www.baeldung.com/java-executor-wait-for-threads)
|
|
||||||
- [wait and notify() Methods in Java](http://www.baeldung.com/java-wait-notify)
|
|
||||||
- [Life Cycle of a Thread in Java](http://www.baeldung.com/java-thread-lifecycle)
|
|
||||||
- [Runnable vs. Callable in Java](http://www.baeldung.com/java-runnable-callable)
|
|
||||||
- [What is Thread-Safety and How to Achieve it?](https://www.baeldung.com/java-thread-safety)
|
- [What is Thread-Safety and How to Achieve it?](https://www.baeldung.com/java-thread-safety)
|
||||||
- [How to Start a Thread in Java](https://www.baeldung.com/java-start-thread)
|
- [How to Start a Thread in Java](https://www.baeldung.com/java-start-thread)
|
||||||
- [How to Delay Code Execution in Java](https://www.baeldung.com/java-delay-code-execution)
|
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
package com.baeldung.concurrent.threadsafety.tests;
|
package com.baeldung.concurrent.threadsafety;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import com.baeldung.concurrent.threadsafety.callables.CounterCallable;
|
import com.baeldung.concurrent.threadsafety.callables.CounterCallable;
|
||||||
import com.baeldung.concurrent.threadsafety.services.Counter;
|
import com.baeldung.concurrent.threadsafety.services.Counter;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
public class CounterTest {
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
public class CounterUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCalledIncrementCounter_thenCorrect() throws Exception {
|
public void whenCalledIncrementCounter_thenCorrect() throws Exception {
|
@ -1,14 +1,16 @@
|
|||||||
package com.baeldung.concurrent.threadsafety.tests;
|
package com.baeldung.concurrent.threadsafety;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import com.baeldung.concurrent.threadsafety.callables.ExtrinsicLockCounterCallable;
|
import com.baeldung.concurrent.threadsafety.callables.ExtrinsicLockCounterCallable;
|
||||||
import com.baeldung.concurrent.threadsafety.services.ExtrinsicLockCounter;
|
import com.baeldung.concurrent.threadsafety.services.ExtrinsicLockCounter;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
public class ExtrinsicLockCounterTest {
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
public class ExtrinsicLockCounterUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCalledIncrementCounter_thenCorrect() throws Exception {
|
public void whenCalledIncrementCounter_thenCorrect() throws Exception {
|
@ -1,13 +1,16 @@
|
|||||||
package com.baeldung.concurrent.threadsafety.tests;
|
package com.baeldung.concurrent.threadsafety;
|
||||||
|
|
||||||
import com.baeldung.concurrent.threadsafety.mathutils.MathUtils;
|
import com.baeldung.concurrent.threadsafety.mathutils.MathUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class MathUtilsTest {
|
public class MathUtilsUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCalledFactorialMethod_thenCorrect() {
|
public void whenCalledFactorialMethod_thenCorrect() {
|
||||||
assertThat(MathUtils.factorial(2)).isEqualTo(2);
|
assertThat(MathUtils.factorial(2)).isEqualTo(new BigInteger("2"));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,14 +1,16 @@
|
|||||||
package com.baeldung.concurrent.threadsafety.tests;
|
package com.baeldung.concurrent.threadsafety;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import com.baeldung.concurrent.threadsafety.callables.MessageServiceCallable;
|
import com.baeldung.concurrent.threadsafety.callables.MessageServiceCallable;
|
||||||
import com.baeldung.concurrent.threadsafety.services.MessageService;
|
import com.baeldung.concurrent.threadsafety.services.MessageService;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
public class MessageServiceTest {
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
public class MessageServiceUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCalledgetMessage_thenCorrect() throws Exception {
|
public void whenCalledgetMessage_thenCorrect() throws Exception {
|
@ -1,14 +1,16 @@
|
|||||||
package com.baeldung.concurrent.threadsafety.tests;
|
package com.baeldung.concurrent.threadsafety;
|
||||||
|
|
||||||
import com.baeldung.concurrent.threadsafety.callables.ReentrantLockCounterCallable;
|
import com.baeldung.concurrent.threadsafety.callables.ReentrantLockCounterCallable;
|
||||||
import com.baeldung.concurrent.threadsafety.services.ReentrantLockCounter;
|
import com.baeldung.concurrent.threadsafety.services.ReentrantLockCounter;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class ReentrantLockCounterTest {
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
public class ReentrantLockCounterUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCalledIncrementCounter_thenCorrect() throws Exception {
|
public void whenCalledIncrementCounter_thenCorrect() throws Exception {
|
@ -1,14 +1,16 @@
|
|||||||
package com.baeldung.concurrent.threadsafety.tests;
|
package com.baeldung.concurrent.threadsafety;
|
||||||
|
|
||||||
import com.baeldung.concurrent.threadsafety.callables.ReentranReadWriteLockCounterCallable;
|
import com.baeldung.concurrent.threadsafety.callables.ReentranReadWriteLockCounterCallable;
|
||||||
import com.baeldung.concurrent.threadsafety.services.ReentrantReadWriteLockCounter;
|
import com.baeldung.concurrent.threadsafety.services.ReentrantReadWriteLockCounter;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class ReentrantReadWriteLockCounterTest {
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
public class ReentrantReadWriteLockCounterUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCalledIncrementCounter_thenCorrect() throws Exception {
|
public void whenCalledIncrementCounter_thenCorrect() throws Exception {
|
||||||
@ -16,9 +18,9 @@ public class ReentrantReadWriteLockCounterTest {
|
|||||||
ReentrantReadWriteLockCounter counter = new ReentrantReadWriteLockCounter();
|
ReentrantReadWriteLockCounter counter = new ReentrantReadWriteLockCounter();
|
||||||
Future<Integer> future1 = (Future<Integer>) executorService.submit(new ReentranReadWriteLockCounterCallable(counter));
|
Future<Integer> future1 = (Future<Integer>) executorService.submit(new ReentranReadWriteLockCounterCallable(counter));
|
||||||
Future<Integer> future2 = (Future<Integer>) executorService.submit(new ReentranReadWriteLockCounterCallable(counter));
|
Future<Integer> future2 = (Future<Integer>) executorService.submit(new ReentranReadWriteLockCounterCallable(counter));
|
||||||
|
|
||||||
assertThat(future1.get()).isEqualTo(1);
|
|
||||||
assertThat(future2.get()).isEqualTo(2);
|
assertThat(future2.get()).isEqualTo(2);
|
||||||
|
assertThat(future1.get()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
2
pom.xml
2
pom.xml
@ -407,6 +407,7 @@
|
|||||||
<module>core-java-modules/core-java-collections-array-list</module>
|
<module>core-java-modules/core-java-collections-array-list</module>
|
||||||
<module>core-java-modules/core-java-collections-set</module>
|
<module>core-java-modules/core-java-collections-set</module>
|
||||||
<module>core-java-modules/core-java-concurrency-basic</module>
|
<module>core-java-modules/core-java-concurrency-basic</module>
|
||||||
|
<module>core-java-modules/core-java-concurrency-basic-2</module>
|
||||||
<module>core-java-modules/core-java-concurrency-collections</module>
|
<module>core-java-modules/core-java-concurrency-collections</module>
|
||||||
<module>core-java-modules/core-java-io</module>
|
<module>core-java-modules/core-java-io</module>
|
||||||
<module>core-java-modules/core-java-io-files</module>
|
<module>core-java-modules/core-java-io-files</module>
|
||||||
@ -1146,6 +1147,7 @@
|
|||||||
<module>core-java-modules/core-java-collections-array-list</module>
|
<module>core-java-modules/core-java-collections-array-list</module>
|
||||||
<module>core-java-modules/core-java-collections-set</module>
|
<module>core-java-modules/core-java-collections-set</module>
|
||||||
<module>core-java-modules/core-java-concurrency-basic</module>
|
<module>core-java-modules/core-java-concurrency-basic</module>
|
||||||
|
<module>core-java-modules/core-java-concurrency-basic-2</module>
|
||||||
<module>core-java-modules/core-java-concurrency-collections</module>
|
<module>core-java-modules/core-java-concurrency-collections</module>
|
||||||
<module>core-java-modules/core-java-io</module>
|
<module>core-java-modules/core-java-io</module>
|
||||||
<module>core-java-modules/core-java-io-files</module>
|
<module>core-java-modules/core-java-io-files</module>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user