Skip to content

Commit ea9cbf0

Browse files
author
Ram swaroop
committed
threads : initial commit
1 parent 647b942 commit ea9cbf0

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

_posts/2015-08-24-threads.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
layout: post
3+
title: Threads
4+
---
5+
6+
A __Thread__ in Java means two different things:
7+
8+
* An instance of class `java.lang.Thread`
9+
* A thread of execution
10+
11+
An __instance of Thread__ is just an object. Like any other object in Java, it has variables and methods, and lives and
12+
dies on the heap. But a __thread of execution__ is an individual process (a "lightweight" process) that has its own call
13+
stack.
14+
15+
In Java, there is one thread per call stack or you can say, one call stack per thread. Even if you don't create any new
16+
threads in your program, threads are back there running. The main() method, that starts the whole ball rolling, runs in
17+
one thread, called (surprisingly) the main thread.
18+
19+
### Two ways to create a Thread in Java
20+
21+
* Extend the `java.lang.Thread` class
22+
* Implement the `Runnable` interface
23+
24+
25+
26+
27+
28+

0 commit comments

Comments
 (0)