diff --git a/java-callable-and-future-examples/Readme.md b/java-callable-and-future-examples/Readme.md deleted file mode 100644 index e69de29..0000000 diff --git a/java-callable-and-future-examples/src/FutureAndCallableExample.java b/java-callable-and-future-examples/src/FutureAndCallableExample.java index 0318dd4..784a482 100644 --- a/java-callable-and-future-examples/src/FutureAndCallableExample.java +++ b/java-callable-and-future-examples/src/FutureAndCallableExample.java @@ -9,12 +9,12 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc Callable callable = () -> { // Perform some computation - System.out.println("Entered Callable"); + System.out.println("Entered Callable"); Thread.sleep(2000); return "Hello from Callable"; }; - System.out.println("Submitting Callable"); + System.out.println("Submitting Callable"); Future future = executorService.submit(callable); // This line executes immediately System.out.println("Do something else while callable is getting executed"); diff --git a/java-callable-and-future-examples/src/FutureCancelExample.java b/java-callable-and-future-examples/src/FutureCancelExample.java index 915f797..1d6456f 100644 --- a/java-callable-and-future-examples/src/FutureCancelExample.java +++ b/java-callable-and-future-examples/src/FutureCancelExample.java @@ -16,7 +16,7 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc long startTime = System.nanoTime(); Future future = executorService.submit(callable); - while(!future.isDone()) { + while (!future.isDone()) { System.out.println("Task is still not done..."); Thread.sleep(200); double elapsedTimeInSec = (System.nanoTime() - startTime) / 1000000000.0; @@ -28,7 +28,7 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc } // Check if future is cancelled before retrieving the result - if(!future.isCancelled()) { + if (!future.isCancelled()) { System.out.println("Task completed! Retrieving the result"); // Future.get() blocks until the result is available String result = future.get(); diff --git a/java-callable-and-future-examples/src/FutureIsDoneExample.java b/java-callable-and-future-examples/src/FutureIsDoneExample.java index 21e8d1a..afd4860 100644 --- a/java-callable-and-future-examples/src/FutureIsDoneExample.java +++ b/java-callable-and-future-examples/src/FutureIsDoneExample.java @@ -12,7 +12,7 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc return "Hello from Callable"; }); - while(!future.isDone()) { + while (!future.isDone()) { System.out.println("Task is still not done..."); Thread.sleep(200); } diff --git a/java-callable-and-future-examples/src/InvokeAllExample.java b/java-callable-and-future-examples/src/InvokeAllExample.java index f27caf5..e56ddc2 100644 --- a/java-callable-and-future-examples/src/InvokeAllExample.java +++ b/java-callable-and-future-examples/src/InvokeAllExample.java @@ -28,11 +28,11 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc List> futures = executorService.invokeAll(taskList); - for(Future future: futures) { + for (Future future : futures) { // The result is printed only after all the futures are complete. (i.e. after 5 seconds) System.out.println(future.get()); } - executorService.shutdown(); + executorService.shutdown(); } } diff --git a/java-callable-and-future-examples/src/InvokeAnyExample.java b/java-callable-and-future-examples/src/InvokeAnyExample.java index 0155340..b667c95 100644 --- a/java-callable-and-future-examples/src/InvokeAnyExample.java +++ b/java-callable-and-future-examples/src/InvokeAnyExample.java @@ -29,6 +29,6 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc System.out.println(result); - executorService.shutdown(); + executorService.shutdown(); } } diff --git a/java-concurrency-issues-and-synchronization/Readme.md b/java-concurrency-issues-and-synchronization/Readme.md deleted file mode 100644 index e69de29..0000000 diff --git a/java-concurrency-issues-and-synchronization/src/MemoryConsistencyErrorExample.java b/java-concurrency-issues-and-synchronization/src/MemoryConsistencyErrorExample.java index 3937668..bff2186 100644 --- a/java-concurrency-issues-and-synchronization/src/MemoryConsistencyErrorExample.java +++ b/java-concurrency-issues-and-synchronization/src/MemoryConsistencyErrorExample.java @@ -1,20 +1,21 @@ public class MemoryConsistencyErrorExample { + private static boolean sayHello = false; public static void main(String[] args) throws InterruptedException { Thread thread = new Thread(() -> { - while(!sayHello) { + while (!sayHello) { - } + } - System.out.println("Hello World!"); + System.out.println("Hello World!"); - while(sayHello) { + while (sayHello) { - } + } - System.out.println("Good Bye!"); + System.out.println("Good Bye!"); }); thread.start(); diff --git a/java-concurrency-issues-and-synchronization/src/RaceConditionExample.java b/java-concurrency-issues-and-synchronization/src/RaceConditionExample.java index 79eb1fd..95d4d58 100644 --- a/java-concurrency-issues-and-synchronization/src/RaceConditionExample.java +++ b/java-concurrency-issues-and-synchronization/src/RaceConditionExample.java @@ -24,7 +24,7 @@ public static void main(String[] args) throws InterruptedException { Counter counter = new Counter(); - for(int i = 0; i < 1000; i++) { + for (int i = 0; i < 1000; i++) { executorService.submit(() -> counter.increment()); } diff --git a/java-concurrency-issues-and-synchronization/src/SynchronizedBlockExample.java b/java-concurrency-issues-and-synchronization/src/SynchronizedBlockExample.java index c661faf..1870c27 100644 --- a/java-concurrency-issues-and-synchronization/src/SynchronizedBlockExample.java +++ b/java-concurrency-issues-and-synchronization/src/SynchronizedBlockExample.java @@ -21,11 +21,12 @@ public int getCount() { } public class SynchronizedBlockExample { + public static void main(String[] args) throws InterruptedException { ExecutorService executorService = Executors.newFixedThreadPool(10); FineGrainedSynchronizedCounter counter = new FineGrainedSynchronizedCounter(); - for(int i = 0; i < 1000; i++) { + for (int i = 0; i < 1000; i++) { executorService.submit(() -> counter.increment()); } diff --git a/java-concurrency-issues-and-synchronization/src/SynchronizedMethodExample.java b/java-concurrency-issues-and-synchronization/src/SynchronizedMethodExample.java index d07c6a6..0135b2d 100644 --- a/java-concurrency-issues-and-synchronization/src/SynchronizedMethodExample.java +++ b/java-concurrency-issues-and-synchronization/src/SynchronizedMethodExample.java @@ -10,7 +10,7 @@ class SynchronizedCounter { // Synchronized Method public synchronized void increment() { - System.out.println(Thread.currentThread().getName()); + System.out.println(Thread.currentThread().getName()); count = count + 1; } @@ -25,7 +25,7 @@ public static void main(String[] args) throws InterruptedException { SynchronizedCounter synchronizedCounter = new SynchronizedCounter(); - for(int i = 0; i < 1000; i++) { + for (int i = 0; i < 1000; i++) { executorService.submit(() -> synchronizedCounter.increment()); } diff --git a/java-concurrency-issues-and-synchronization/src/VolatileKeywordExample.java b/java-concurrency-issues-and-synchronization/src/VolatileKeywordExample.java index 64f8c9c..f0dbb0a 100644 --- a/java-concurrency-issues-and-synchronization/src/VolatileKeywordExample.java +++ b/java-concurrency-issues-and-synchronization/src/VolatileKeywordExample.java @@ -4,17 +4,17 @@ public class VolatileKeywordExample { public static void main(String[] args) throws InterruptedException { Thread thread = new Thread(() -> { - while(!sayHello) { + while (!sayHello) { - } + } - System.out.println("Hello World!"); + System.out.println("Hello World!"); - while(sayHello) { + while (sayHello) { - } + } - System.out.println("Good Bye!"); + System.out.println("Good Bye!"); }); thread.start(); diff --git a/java-executors-and-thread-pool/Readme.md b/java-executors-and-thread-pool/Readme.md deleted file mode 100644 index e69de29..0000000 diff --git a/java-lock-objects-and-atomic-variables/Readme.md b/java-lock-objects-and-atomic-variables/Readme.md deleted file mode 100644 index e69de29..0000000 diff --git a/java-lock-objects-and-atomic-variables/src/AtomicIntegerExample.java b/java-lock-objects-and-atomic-variables/src/AtomicIntegerExample.java index 46cc032..c399f07 100644 --- a/java-lock-objects-and-atomic-variables/src/AtomicIntegerExample.java +++ b/java-lock-objects-and-atomic-variables/src/AtomicIntegerExample.java @@ -25,7 +25,7 @@ public static void main(String[] args) throws InterruptedException { AtomicCounter atomicCounter = new AtomicCounter(); - for(int i = 0; i < 1000; i++) { + for (int i = 0; i < 1000; i++) { executorService.submit(() -> atomicCounter.incrementAndGet()); } diff --git a/java-lock-objects-and-atomic-variables/src/ReadWriteLockExample.java b/java-lock-objects-and-atomic-variables/src/ReadWriteLockExample.java index 2b60d85..2f30d95 100644 --- a/java-lock-objects-and-atomic-variables/src/ReadWriteLockExample.java +++ b/java-lock-objects-and-atomic-variables/src/ReadWriteLockExample.java @@ -13,7 +13,6 @@ class ReadWriteCounter { public int incrementAndGetCount() { lock.writeLock().lock(); - try { count = count + 1; return count; @@ -40,8 +39,8 @@ public static void main(String[] args) { ReadWriteCounter counter = new ReadWriteCounter(); Runnable readTask = () -> { - System.out.println(Thread.currentThread().getName() + - " Read Task : " + counter.getCount()); + System.out.println(Thread.currentThread().getName() + + " Read Task : " + counter.getCount()); }; Runnable writeTask = () -> { diff --git a/java-lock-objects-and-atomic-variables/src/ReentrantLockExample.java b/java-lock-objects-and-atomic-variables/src/ReentrantLockExample.java index 26441aa..8725ed4 100644 --- a/java-lock-objects-and-atomic-variables/src/ReentrantLockExample.java +++ b/java-lock-objects-and-atomic-variables/src/ReentrantLockExample.java @@ -37,7 +37,7 @@ public static void main(String[] args) throws InterruptedException { executorService.submit(() -> counter.increment()); - for(int i = 0; i < 10; i++) { + for (int i = 0; i < 10; i++) { executorService.submit(() -> counter.increment()); } diff --git a/java-lock-objects-and-atomic-variables/src/ReentrantLockMethodsExample.java b/java-lock-objects-and-atomic-variables/src/ReentrantLockMethodsExample.java index ddbb34f..bb1fd41 100644 --- a/java-lock-objects-and-atomic-variables/src/ReentrantLockMethodsExample.java +++ b/java-lock-objects-and-atomic-variables/src/ReentrantLockMethodsExample.java @@ -24,7 +24,7 @@ public int incrementAndGet() { throw new IllegalStateException(e); } - if(isAcquired) { + if (isAcquired) { try { Thread.sleep(2000); count = count + 1; @@ -46,8 +46,8 @@ public static void main(String[] args) { ReentrantLockMethodsCounter lockMethodsCounter = new ReentrantLockMethodsCounter(); executorService.submit(() -> { - System.out.println("IncrementCount (First Thread) : " + - lockMethodsCounter.incrementAndGet() + "\n"); + System.out.println("IncrementCount (First Thread) : " + + lockMethodsCounter.incrementAndGet() + "\n"); }); executorService.submit(() -> { diff --git a/java-thread-and-runnable-examples/Readme.md b/java-thread-and-runnable-examples/Readme.md deleted file mode 100644 index e69de29..0000000