• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Java threads and fork concept

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just wanted to know what is the comparison of Threads in Java and forking concept in Unix.
As far as I know, correct me if I am wrong

Forking is multiprocessing. When you fork a child process (not thread) get's created. The the child process will not share any resources with the parent process from which it got created through forking.

But this is not the case with the Threads in Java.When you create threads, there share the same process resources.

Am I right? Is it proper to compare the Threads of Java and Fork. Or is it like Apple to Orange comparison. I need some proper perspective about this.

Thanks,
 
Marshal
Posts: 75836
361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did this tutorial help at all?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anil Deshpande wrote:Am I right? Is it proper to compare the Threads of Java and Fork. Or is it like Apple to Orange comparison. I need some proper perspective about this.


I'd definitely look at Campbell's link, but the functional difference is that what a Thread (or Runtime; and I'd advise you to use the latter) does is independent of the Thread that spawned it.

In languages that implement fork() in it's usual form, it spawns an identical process (of some kind, heavy- or lightweight) that continues on from where the fork() was encountered, usually with a copy of all the process state information at that time.

Java Threads, on the other hand, can process code that is entirely different from the Thread that spawned them, but what they usually (and I say this because I'm NOT a Java multi-threading expert) share/clone is the environment of the spawning Thread (current directory, critical variable states ... things like that).

As to details, you really do need to check the tutorials (or the JLS).

HIH

Winston
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On most modern operating systems, a process is a program running on a computer, that is separate from other processes running on the computer. Each process has its own address space and other resources, and it cannot access the address space and other resources of other processes directly.

When you fork a process the Unix way, what happens is that a second copy of the program starts running, completely separate from the original copy that was running.

Threads are are more lightweight way to do multiprocessing. One process can have multiple threads running at the same time. All threads share the address space and other resources of the process; different threads in the same process can directly access each other's data.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:different threads in the same process can directly access each other's data.


Good point. Glad I used Thread, not 'thread'.

Winston
 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot.. the tutorial also helped
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic