JAVA-12045 : move java concurrency ebook content code to common module (#12559)

* JAVA-12045 : move java concurrency ebook content code to common module

* JAVA-12045: addressed the review comments .. renamed package names and placed core-java-concurrency-simple module in pom.xml

* JAVA-12045: removed duplicate module after renaming java-simple-module to core-java-simple-module
This commit is contained in:
Keerthi
2022-08-08 23:26:55 +10:00
committed by GitHub
parent 9528c51654
commit cdb19ff6d5
36 changed files with 45 additions and 8 deletions
@@ -1,55 +0,0 @@
package com.baeldung.concurrent.volatilekeyword;
import org.junit.Test;
import static org.junit.Assert.*;
public class SharedObjectManualTest {
@Test
public void whenOneThreadWrites_thenVolatileReadsFromMainMemory() throws InterruptedException {
SharedObject sharedObject = new SharedObject();
Thread writer = new Thread(() -> sharedObject.incrementCount());
writer.start();
Thread.sleep(100);
Thread readerOne = new Thread(() -> {
int valueReadByThread2 = sharedObject.getCount();
assertEquals(1, valueReadByThread2);
});
readerOne.start();
Thread readerTwo = new Thread(() -> {
int valueReadByThread3 = sharedObject.getCount();
assertEquals(1, valueReadByThread3);
});
readerTwo.start();
}
@Test
public void whenTwoThreadWrites_thenVolatileReadsFromMainMemory() throws InterruptedException {
SharedObject sharedObject = new SharedObject();
Thread writerOne = new Thread(() -> sharedObject.incrementCount());
writerOne.start();
Thread.sleep(100);
Thread writerTwo = new Thread(() -> sharedObject.incrementCount());
writerTwo.start();
Thread.sleep(100);
Thread readerOne = new Thread(() -> {
int valueReadByThread2 = sharedObject.getCount();
assertEquals(2, valueReadByThread2);
});
readerOne.start();
Thread readerTwo = new Thread(() -> {
int valueReadByThread3 = sharedObject.getCount();
assertEquals(2, valueReadByThread3);
});
readerTwo.start();
}
}