[JAVA-13960] Clean up (#12994)
* [JAVA-13960] Clean up * [JAVA-13960] Rename classes Co-authored-by: panagiotiskakos <panagiotis.kakos@libra-is.com>
This commit is contained in:
parent
fc0c16a3ae
commit
ca436ff5e0
|
@ -1,6 +1,6 @@
|
|||
package com.baeldung.concurrent.synchronize;
|
||||
|
||||
public class BaeldungSynchronizedBlocks {
|
||||
public class SynchronizedBlocks {
|
||||
|
||||
private int count = 0;
|
||||
private static int staticCount = 0;
|
||||
|
@ -12,7 +12,7 @@ public class BaeldungSynchronizedBlocks {
|
|||
}
|
||||
|
||||
static void performStaticSyncTask() {
|
||||
synchronized (BaeldungSynchronizedBlocks.class) {
|
||||
synchronized (SynchronizedBlocks.class) {
|
||||
setStaticCount(getStaticCount() + 1);
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,6 @@ public class BaeldungSynchronizedBlocks {
|
|||
}
|
||||
|
||||
private static void setStaticCount(int staticCount) {
|
||||
BaeldungSynchronizedBlocks.staticCount = staticCount;
|
||||
SynchronizedBlocks.staticCount = staticCount;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.baeldung.concurrent.synchronize;
|
||||
|
||||
public class BaeldungSynchronizedMethods {
|
||||
public class SynchronizedMethods {
|
||||
|
||||
private int sum = 0;
|
||||
private int syncSum = 0;
|
|
@ -9,12 +9,12 @@ import java.util.stream.IntStream;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class BaeldungSychronizedBlockUnitTest {
|
||||
public class SynchronizedBlocksUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenMultiThread_whenBlockSync() throws InterruptedException {
|
||||
ExecutorService service = Executors.newFixedThreadPool(3);
|
||||
BaeldungSynchronizedBlocks synchronizedBlocks = new BaeldungSynchronizedBlocks();
|
||||
SynchronizedBlocks synchronizedBlocks = new SynchronizedBlocks();
|
||||
|
||||
IntStream.range(0, 1000)
|
||||
.forEach(count -> service.submit(synchronizedBlocks::performSynchronisedTask));
|
||||
|
@ -28,10 +28,10 @@ public class BaeldungSychronizedBlockUnitTest {
|
|||
ExecutorService service = Executors.newCachedThreadPool();
|
||||
|
||||
IntStream.range(0, 1000)
|
||||
.forEach(count -> service.submit(BaeldungSynchronizedBlocks::performStaticSyncTask));
|
||||
.forEach(count -> service.submit(SynchronizedBlocks::performStaticSyncTask));
|
||||
service.awaitTermination(500, TimeUnit.MILLISECONDS);
|
||||
|
||||
assertEquals(1000, BaeldungSynchronizedBlocks.getStaticCount());
|
||||
assertEquals(1000, SynchronizedBlocks.getStaticCount());
|
||||
}
|
||||
|
||||
@Test
|
|
@ -10,13 +10,13 @@ import java.util.stream.IntStream;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class BaeldungSynchronizeMethodsUnitTest {
|
||||
public class SynchronizedMethodsUnitTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void givenMultiThread_whenNonSyncMethod() throws InterruptedException {
|
||||
ExecutorService service = Executors.newFixedThreadPool(3);
|
||||
BaeldungSynchronizedMethods method = new BaeldungSynchronizedMethods();
|
||||
SynchronizedMethods method = new SynchronizedMethods();
|
||||
|
||||
IntStream.range(0, 1000)
|
||||
.forEach(count -> service.submit(method::calculate));
|
||||
|
@ -28,7 +28,7 @@ public class BaeldungSynchronizeMethodsUnitTest {
|
|||
@Test
|
||||
public void givenMultiThread_whenMethodSync() throws InterruptedException {
|
||||
ExecutorService service = Executors.newFixedThreadPool(3);
|
||||
BaeldungSynchronizedMethods method = new BaeldungSynchronizedMethods();
|
||||
SynchronizedMethods method = new SynchronizedMethods();
|
||||
|
||||
IntStream.range(0, 1000)
|
||||
.forEach(count -> service.submit(method::synchronisedCalculate));
|
||||
|
@ -42,10 +42,10 @@ public class BaeldungSynchronizeMethodsUnitTest {
|
|||
ExecutorService service = Executors.newCachedThreadPool();
|
||||
|
||||
IntStream.range(0, 1000)
|
||||
.forEach(count -> service.submit(BaeldungSynchronizedMethods::syncStaticCalculate));
|
||||
.forEach(count -> service.submit(SynchronizedMethods::syncStaticCalculate));
|
||||
service.awaitTermination(100, TimeUnit.MILLISECONDS);
|
||||
|
||||
assertEquals(1000, BaeldungSynchronizedMethods.staticSum);
|
||||
assertEquals(1000, SynchronizedMethods.staticSum);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue