forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split or move core-java-modules/core-java-concurrency-basic module (e…
- Loading branch information
1 parent
dac59fb
commit 6073d2d
Showing
30 changed files
with
112 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions
19
core-java-modules/core-java-concurrency-basic-2/src/main/resources/logback.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions
8
...waitandnotify/NetworkIntegrationTest.java → ...waitandnotify/NetworkIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
...rrent/threadsafety/tests/CounterTest.java → ...current/threadsafety/CounterUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
...afety/tests/ExtrinsicLockCounterTest.java → ...dsafety/ExtrinsicLockCounterUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
...ent/threadsafety/tests/MathUtilsTest.java → ...rrent/threadsafety/MathUtilsUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
package com.baeldung.concurrent.threadsafety.tests; | ||
package com.baeldung.concurrent.threadsafety; | ||
|
||
import com.baeldung.concurrent.threadsafety.mathutils.MathUtils; | ||
import org.junit.Test; | ||
|
||
import java.math.BigInteger; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class MathUtilsTest { | ||
public class MathUtilsUnitTest { | ||
|
||
@Test | ||
public void whenCalledFactorialMethod_thenCorrect() { | ||
assertThat(MathUtils.factorial(2)).isEqualTo(2); | ||
assertThat(MathUtils.factorial(2)).isEqualTo(new BigInteger("2")); | ||
} | ||
} |
10 changes: 6 additions & 4 deletions
10
...hreadsafety/tests/MessageServiceTest.java → .../threadsafety/MessageServiceUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
...afety/tests/ReentrantLockCounterTest.java → ...dsafety/ReentrantLockCounterUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 7 additions & 5 deletions
12
...ts/ReentrantReadWriteLockCounterTest.java → ...eentrantReadWriteLockCounterUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
package com.baeldung.concurrent.threadsafety.tests; | ||
package com.baeldung.concurrent.threadsafety; | ||
|
||
import com.baeldung.concurrent.threadsafety.callables.ReentranReadWriteLockCounterCallable; | ||
import com.baeldung.concurrent.threadsafety.services.ReentrantReadWriteLockCounter; | ||
import org.junit.Test; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import org.junit.Test; | ||
|
||
public class ReentrantReadWriteLockCounterTest { | ||
public class ReentrantReadWriteLockCounterUnitTest { | ||
|
||
@Test | ||
public void whenCalledIncrementCounter_thenCorrect() throws Exception { | ||
ExecutorService executorService = Executors.newFixedThreadPool(2); | ||
ReentrantReadWriteLockCounter counter = new ReentrantReadWriteLockCounter(); | ||
Future<Integer> future1 = (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(future1.get()).isEqualTo(1); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters