While going through most java tutorials, they mention threads as light weight process. I know what's happening in thread creation, but I didn't get the definition of thread. In stackoverflow most of the time answered this question also. But that also I'm confusing. Couldn't get the real idea behind "Light weight process". Can anyone explain simplest way what is meaning of "thread is light weight process" ?
-
@PaRiMaLRaJ I saw it. But that doesn't give me clear idea. Can't thread have more weight? Can't thread have lot of processes to accomplish? Lot of task to accomplish mean big weight process or not ? That answer didn't solve my problem. – Maduri Oct 05 '14 at 08:37
3 Answers
A process has different memory zones. Depending on the OS, some may be grouped, non existent, or even sub-splitted :
- code
- memory (for variables)
- stack
- heap (for dynamical allocation)
When you create a new process, the system has to allocate all of that. For a thread, only a new stack is allocated, the head on memory are common to all threads of same process.

- 143,923
- 11
- 122
- 252
You might call it that way because a thread, like a process, is a way to have a parallel, concurrrent, flow of execution. But contrary to a process, a thread shares the same memory as the other threads in the same process, instead of having a completely separate memory.

- 678,734
- 91
- 1,224
- 1,255
-
ok dear. Share memory means I think other thread also can access that memory. But why we say "Light Weight" ? Can't thread have high/big weight? Can't thread do very heavy process? – Maduri Oct 05 '14 at 08:22
-
6@Maduri light weight in this context means that there is generally a lot less overhead involved in creating a thread or switching execution between threads than with separate processes. The exact amount of overhead in either case heavily depends on the operating system. – Thomas Stets Oct 05 '14 at 08:36
-
@ThomasStets I think you are solve my problem some extent. Thanx lot dear. "creating a thread or switching execution between threads" That means light weight doesn't mean that number of task that thread have to fulfill.Am I correct? Light weight means load between switching or execution? Another problem is if that thread have lot of task then execution how become efficient/light weight? – Maduri Oct 05 '14 at 08:55
-
2@Maduri it effectively means, that the operating system can create a thread much faster than it can create a process, and that it can switch between threads faster than between processes. Which means, more CPU time for your program logic. – Thomas Stets Oct 05 '14 at 09:24
-
@ThomasStets Thanx lot dear. I got the idea :) .You solved my big issue. Have a nice day :) . – Maduri Oct 05 '14 at 09:37
I guess that explanation is rising from the fact that threads generated by a parent process use the same address space in memory. On the other hand, each process has its own address space. Based on this fact, a context switch for a process is much heavier than context switch for a thread.

- 4,239
- 3
- 28
- 51