Skip to content

Commit 460eb93

Browse files
committed
Did a first code inspection tour
Corrected some typos Emptied some auto-generated catch sections and renamed the exception variable to "ignored"
1 parent 240fbb2 commit 460eb93

File tree

14 files changed

+41
-53
lines changed

14 files changed

+41
-53
lines changed

JavaMultiThreadingCodes/src/CallableAndFuture_13/CallableTester.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Runnable Introduced in Java 1.0 Callable<T> Introduced in Java 1.5 as part of
1919
* java.util.concurrent library
2020
*
21-
* Runnable cannot be parameterized Callable is a parameterized type whose type
21+
* Runnable cannot be parametrized Callable is a parametrized type whose type
2222
* parameter indicates the return type of its run method Classes implementing
2323
*
2424
* Runnable needs to implement run() method, classes implementing Callable needs

JavaMultiThreadingCodes/src/CountDownLatch_6/App.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ public void run() {
4545

4646
try {
4747
Thread.sleep(3000);
48-
} catch (InterruptedException e) {
49-
// TODO Auto-generated catch block
50-
e.printStackTrace();
51-
}
48+
} catch (InterruptedException ignored) {}
5249
latch.countDown();
5350
}
5451
}
@@ -62,7 +59,7 @@ public static void main(String[] args) {
6259
executor.submit(new Processor(latch));
6360
}
6461
try {
65-
// Application’s main thread waits, till other service threads which are
62+
// Application’s main thread waits, till other service threads which are
6663
// as an example responsible for starting framework services have completed started all services.
6764
latch.await();
6865
} catch (InterruptedException e) {

JavaMultiThreadingCodes/src/Deadlock_11/Runner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private void acquireLocks(Lock firstLock, Lock secondLock) throws InterruptedExc
5353
}
5454
}
5555

56-
//firstThreaad runs
56+
//firstThread runs
5757
public void firstThread() throws InterruptedException {
5858
Random random = new Random();
5959
for (int i = 0; i < 10000; i++) {

JavaMultiThreadingCodes/src/Deadlock_11/SimpleDeadLock.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
*/
1111
public class SimpleDeadLock {
1212

13-
public static Object lock1 = new Object();
14-
public static Object lock2 = new Object();
13+
public static final Object lock1 = new Object();
14+
public static final Object lock2 = new Object();
1515
private int index;
1616

1717
public static void main(String[] a) {
@@ -28,7 +28,7 @@ public void run() {
2828
System.out.println("Thread 1: Holding lock 1...");
2929
try {
3030
Thread.sleep(10);
31-
} catch (InterruptedException e) {
31+
} catch (InterruptedException ignored) {
3232
}
3333
System.out.println("Thread 1: Waiting for lock 2...");
3434
synchronized (lock2) {
@@ -45,7 +45,7 @@ public void run() {
4545
System.out.println("Thread 2: Holding lock 2...");
4646
try {
4747
Thread.sleep(10);
48-
} catch (InterruptedException e) {
48+
} catch (InterruptedException ignored) {
4949
}
5050
System.out.println("Thread 2: Waiting for lock 1...");
5151
synchronized (lock1) {

JavaMultiThreadingCodes/src/InterruptingThreads14/App.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public static void main(String[] args) throws InterruptedException {
3131

3232
System.out.println("Starting.");
3333

34-
ExecutorService executer = Executors.newCachedThreadPool();
34+
ExecutorService executor = Executors.newCachedThreadPool();
3535

36-
Future<?> fu = executer.submit(new Callable<Void>() {
36+
Future<?> fu = executor.submit(new Callable<Void>() {
3737

3838
@Override
3939
public Void call() throws Exception {
@@ -49,11 +49,11 @@ public Void call() throws Exception {
4949
}
5050
});
5151

52-
executer.shutdown();
52+
executor.shutdown();
5353
Thread.sleep(500);
54-
executer.shutdownNow();
54+
executor.shutdownNow();
5555

56-
executer.awaitTermination(1, TimeUnit.DAYS);
56+
executor.awaitTermination(1, TimeUnit.DAYS);
5757
System.out.println("Finished.");
5858
}
5959

JavaMultiThreadingCodes/src/JoiningAndSynchronizeThreads_3/Worker.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ public void run() {
7070
try {
7171
thread1.join();
7272
thread2.join();
73-
} catch (InterruptedException e) {
74-
// TODO Auto-generated catch block
75-
e.printStackTrace();
76-
}
73+
} catch (InterruptedException ignored) {}
7774
System.out.println("Count is: " + count);
7875
}
7976
}

JavaMultiThreadingCodes/src/LockObjects_4/Worker.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public class Worker {
2121

2222
private Random random = new Random();
2323

24-
private Object lock1 = new Object();
25-
private Object lock2 = new Object();
24+
private final Object lock1 = new Object();
25+
private final Object lock2 = new Object();
2626

27-
private List<Integer> list1 = new ArrayList<Integer>();
28-
private List<Integer> list2 = new ArrayList<Integer>();
27+
private List<Integer> list1 = new ArrayList<>();
28+
private List<Integer> list2 = new ArrayList<>();
2929

3030
public void stageOne() {
3131

JavaMultiThreadingCodes/src/LockObjects_4/WorkerMethodsSynchronized.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public class WorkerMethodsSynchronized {
2121

2222
private Random random = new Random();
2323

24-
private List<Integer> list1 = new ArrayList<Integer>();
25-
private List<Integer> list2 = new ArrayList<Integer>();
24+
private List<Integer> list1 = new ArrayList<>();
25+
private List<Integer> list2 = new ArrayList<>();
2626

2727
/**
2828
* synchronized, methods use different data (list1 list2) so by synchronized
@@ -78,10 +78,7 @@ public void run() {
7878
try {
7979
t1.join();
8080
t2.join();
81-
} catch (InterruptedException e) {
82-
// TODO Auto-generated catch block
83-
e.printStackTrace();
84-
}
81+
} catch (InterruptedException ignored) {}
8582

8683
long end = System.currentTimeMillis();
8784

JavaMultiThreadingCodes/src/LowLevelProducerConsumer_9/Processor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ public class Processor {
1414

1515
private LinkedList<Integer> list = new LinkedList<>();
1616
private final int LIMIT = 10;
17-
private Object lock = new Object();
17+
private final Object lock = new Object();
1818

1919
public void produce() throws InterruptedException {
2020
int value = 0;
2121
while (true) {
2222
synchronized (lock) {
23-
//whenever the threade is notofied starts again from the loop
23+
//whenever the thread is notified starts again from the loop
2424
while (list.size() == LIMIT) {
2525
lock.wait();// wait() is also true
2626
}

JavaMultiThreadingCodes/src/Semaphores_12/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class App {
4040

4141
public static void main(String[] args) throws Exception {
4242
ExecutorService executor = Executors.newCachedThreadPool();
43-
for (int i = 0; i < 13; i++) { //200 hundred times will be calleds
43+
for (int i = 0; i < 13; i++) { //200 hundred times will be called
4444
executor.submit(new Runnable() {
4545
public void run() {
4646
Connection.getInstance().connect();

0 commit comments

Comments
 (0)