File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Difference between Thread & Process Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Difference between Thread & Process" Watch "Difference between Thread & Process" New topic
Author

Difference between Thread & Process

Mukesh Rathod
Ranch Hand

Joined: Oct 11, 2000
Posts: 32

Can anyone tell about the difference between a Thread and a process?
I was asked this question in one of the interview.
Thanks in advance.
Mukesh
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1831
Hi ,
Mukesh you can check out the link here for some info http://www.javaranch.com/ubb/Forum27/HTML/000057.html
Mukesh Rathod
Ranch Hand

Joined: Oct 11, 2000
Posts: 32
Hi Rahul,
Thanks for repy.
Can you please give me some link to reading material on Process?
mukesh
Jerry Pulley
Ranch Hand

Joined: Sep 19, 2000
Posts: 221
Mukesh,
In a nutshell, a process can contain multiple threads.
In most multithreading operating systems, a process gets its own memory address space; a thread doesn't. Threads typically share the heap belonging to their parent process.
For instance, a JVM runs in a single process in the host O/S. Threads in the JVM share the heap belonging to that process; that's why several threads may access the same object.
Typically, even though they share a common heap, threads have their own stack space. This is how one thread's invocation of a method is kept separate from another's.
This is all a gross oversimplification, but it's accurate enough at a high level. Lots of details differ between operating systems.
jply
Mukesh Rathod
Ranch Hand

Joined: Oct 11, 2000
Posts: 32
Hi Jerry
Thanks a lot for good explanation.

Mukesh
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6913
Just to complicate this a little, some operating systems (mainly Linux at the moment) provide what is known as "native threads". These share process resources in the same way as threads described above, but also appear in the process listing and may be manipulated using process control tools. Older Linux JVMs used "green threads" which are all hidden inside a single process, but JDK 1.3 uses native threds by default.
A typical comment from someone who has just upgraded to JDK 1.3 might be "How come there are now 5 copies of my Java Virtual Machine running when my application only used to need one?" If you see this kind of thing, don't worry, it's just Linux native threads.


A Convergent Visionary ~ Frank's Punchbarrel Blog ~ LinkedIn profile
mohit joshi
Ranch Hand

Joined: Sep 23, 2000
Posts: 243
Is it true that in java each thread has two stacks. I read something like that in java security book. Can anybody explain how the thread uses two stacks?
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Difference between Thread & Process
 
Similar Threads
Good Java Interview Questions!
thread
Difference bet. Process based Multithreading and Thread based Multithreading?
Process and Thread
process & thread