JavaDoc optimized · kjun25/JavaMultiThreading@b83db5e · GitHub
Skip to content

Commit b83db5e

Browse files
committed
JavaDoc optimized
Added myself to README.md
1 parent bfa2172 commit b83db5e

3 files changed

Lines changed: 53 additions & 48 deletions

File tree

JavaMultiThreadingCodes/src/CallableAndFuture_13/App2.java

Lines changed: 9 additions & 12 deletions
Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
11
package CallableAndFuture_13;
22

3-
import java.util.concurrent.Callable;
4-
import java.util.concurrent.ExecutorService;
5-
import java.util.concurrent.Future;
6-
import java.util.concurrent.ScheduledThreadPoolExecutor;
3+
import java.util.concurrent.*;
74

85
/**
9-
* Source:http://java-x.blogspot.com.tr/2006/11/java-5-concurrency-callable-and-future.html
10-
* Till Java 1.4, threads could be implemented by either implementing Runnable
11-
* or extending Thread. This was quite simple, but had a serious limitation -
6+
* Source:
7+
* <a href="http://java-x.blogspot.com.tr/2006/11/java-5-concurrency-callable-and-future.html">
8+
* http://java-x.blogspot.com.tr/2006/11/java-5-concurrency-callable-and-future.html
9+
* </a>
10+
* <p>
11+
* Till Java 1.4, threads could be implemented by either implementing
12+
* {@link java.lang.Runnable} or extending {@link java.lang.Thread}.
13+
* This was quite simple, but had a serious limitation;
1214
* They have a run method that cannot return values. In order to side-step this,
1315
* most programmers use side-effects (writing to a file etc.) to mimic returning
14-
* values to the invoker of the thread. Java 5 introduces the Callable
15-
* interface, that allows users to return values from a thread
16-
*
17-
* Runnable vs Callable<T>
18-
* Runnable Introduced in Java 1.0 Callable<T> Introduced in Java 1.5 as part of
19-
* java.util.concurrent library
20-
*
21-
* Runnable cannot be parametrized Callable is a parametrized type whose type
22-
* parameter indicates the return type of its run method Classes implementing
23-
*
16+
* values to the invoker of the thread. Java 5 introduces the
17+
* {@link java.util.concurrent.Callable} interface, that allows users to
18+
* return values from a thread.
19+
* </p>
20+
* <p>
21+
* {@link java.lang.Runnable} vs {@link java.util.concurrent.Callable} :
22+
* <ul>
23+
* <li>
24+
* Runnable Introduced in Java 1.0. Callable<T> Introduced in Java 1.5 as
25+
* part of
26+
* {@link java.util.concurrent} library.
27+
* </li>
28+
* <li>
29+
* Runnable cannot be parametrized .Callable is a parametrized type whose type
30+
* parameter indicates the return type of its run method Classes implementing.
31+
* </li>
32+
* <li>
2433
* Runnable needs to implement run() method, classes implementing Callable needs
25-
* to implement call() method
26-
*
27-
* Runnable.run() returns no value, Callable.call() returns a value of Type T
28-
*
34+
* to implement call() method.
35+
* </li>
36+
* <li>
37+
* Runnable.run() returns no value, Callable.call() returns a value of Type T.
38+
* </li>
39+
* <li>
2940
* Runnable can not throw checked exceptions, Callable can throw checked
30-
* exceptions
41+
* exceptions.
42+
* </li>
43+
* </ul>
44+
* </p>
3145
*
3246
* @author Z.B. Celik <celik.berkay@gmail.com>
3347
*/
@@ -58,20 +72,17 @@ public void setMyName(int myName) {
5872

5973
public class CallableTester {
6074

61-
public static void main(String[] args) {
75+
public static void main(String[] args) throws InterruptedException {
6276

6377
Callable<Integer> callable = new CallableImpl(2);
6478
ExecutorService executor = new ScheduledThreadPoolExecutor(1);
6579
Future<Integer> future = executor.submit(callable);
6680

6781
try {
6882
System.out.println("Future value: " + future.get());
69-
} catch (Exception e) {
70-
e.printStackTrace();
71-
} finally {
72-
executor.shutdown();
73-
executor.isTerminated();
74-
}
83+
} catch (Exception ignored) {}
84+
executor.shutdown();
85+
executor.awaitTermination(1, TimeUnit.HOURS);
7586
}
7687

7788
}

README.md

Lines changed: 4 additions & 7 deletions

0 commit comments

Comments
 (0)