| Author |
Threads vs. processes
|
Leena Diwan
Ranch Hand
Joined: Jun 18, 2001
Posts: 349
|
|
I was asked.. what is the diff between a thread and a process ? can anyone help ? Thanks in advance.. Greetings.. Leena
|
[SCJP2, SCWCD1.3, SCBCD]
|
 |
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
|
|
A thread shares its memory space with all other threads living inside the same process. On one hand, this makes it easy for threads to interact with each other as they can simply share data (objects). On the other, if a thread crashes badly it can easily take all other threads down with it. Because threads share so many resources with other threads inside the same process, they are relatively lightweight. A process is isolated as much as possible from other processes by the operating system. In particular processes cannot access each others' memory (although there exists a shared memory facility through which processes can share data). Each process has its owner, security permissions, etc. Processes are considered heavyweight because they are generally expensive to create. - Peter [ April 07, 2002: Message edited by: Peter den Haan ]
|
 |
Mr. C Lamont Gilbert
Ranch Hand
Joined: Oct 05, 2001
Posts: 1158
|
|
Another way to look at it is that a process is a set of code and resources. A thread is something which is running at some point in that code using those resources. You can have multiple threads running within a process. For instance, if you considered a book a process, a thread would be the person reading it. And several different people could read from the same book at the same time.
|
 |
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
|
|
I like your analogy Welcome back, CLG. - Peter
|
 |
 |
|
|
subject: Threads vs. processes
|
|
|