Skip to content

Commit a8441bb

Browse files
author
Ram swaroop
committed
minor typo fixed
1 parent 360c958 commit a8441bb

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

_posts/2015-08-24-threads.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,25 @@ In Java, there is one thread per call stack or you can say, one call stack per t
1616
threads in your program, threads are back there running. The main() method, that starts the whole ball rolling, runs in
1717
one thread, called (surprisingly) the main thread.
1818

19-
### Two ways to create a Thread in Java
19+
### Create a Thread in Java
20+
21+
Either of the 2 ways:
2022

2123
* Extend the `java.lang.Thread` class
2224
* Implement the `Runnable` interface
2325

26+
Though extending the `Thread` class is simple, in real life applications implementing the `Runnable` interface is
27+
the preferred way of creating threads. It's usually not a good OO practice to extend `Thread` because sub-classing
28+
should be reserved for specialized versions of more general superclasses.
29+
30+
So the only time it really makes sense (from an OO perspective) to extend `Thread` is when you have a more specialized
31+
version of a Thread class. In other words, because you have more specialized thread-specific behavior. And if you just
32+
want a job to be done by a thread then you should design a class that implements the Runnable interface, which also
33+
leaves your class free to extend some other class.
34+
35+
### Define a Thread
2436

37+
*
2538

2639

2740

0 commit comments

Comments
 (0)