thread vs fork?

A

Arne Vajhøj

hi, is fork runs faster then thread in java?

I don't understand the question.

The fork join framework does use threads.

It just provides an easy programming model
for writing multithreaded code.

Arne
 
R

Roedy Green

hi, is fork runs faster then thread in java?

There is obviously less overhead with a new thread than forking off a
new process. A thread shares the same pool of objects. A fork has
its own JVM and pool of objects. Forking is usually to code you had
nothing to do with writing or that is written in other languages.
Threads are when the piece of work to do is quite small or needs
access to your object pool.
 
L

Lew

Roedy said:
Peter Cheung wrote, quoted or indirectly quoted someone who said:

There is obviously less overhead with a new thread than forking off a
new process. A thread shares the same pool of objects. A fork has

What does that have to do with Java?

In Java the exact opposite is true:
http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ForkJoinTask.html
"
Abstract base class for tasks that run within a ForkJoinPool. A ForkJoinTask is a thread-like entity that is much lighter weight than a normal thread.Huge numbers of tasks and subtasks may be hosted by a small number of actual threads in a ForkJoinPool, at the price of some usage limitations."
its own JVM and pool of objects. Forking is usually to code you had
nothing to do with writing or that is written in other languages.

Unless, of course, you are talking about forking in the Java sense.
Threads are when the piece of work to do is quite small

No, that's not true at all.

Threads are just fine when the piece of work is large, and in many cases
are motivated by the need to do large pieces of work. The whole idea of
'SwingWorker', for example, is to perform large units of work in a different
thread from the GUI.
or needs access to your object pool.

That is true, assuming you need concurrency.

Well, partially true. In many cases there are non-thread solutions.
 
J

Joshua Cranmer

What does that have to do with Java?

Traditionally, the term "fork" has been used to refer to "creating a new
process" (the traditional way of handling concurrency in Unix code)--the
Unix syscall for this step is literally called "fork." On Unix-based
system, process creation is extremely low overhead, so process-based
parallelism was more common than on Windows where making a new process
is painfully slow.

When I first saw the OP's question, I first thought he was referring to
fork in the process-creation sense, so it's not clear to me offhand if
he is referring to the process-creation fork or Java-framework fork.
 
L

Lew

Joshua said:
Lew said:
Roedy said:
Peter Cheung wrote, quoted or indirectly quoted someone who said:
hi, is fork runs faster then thread in java [sic]?
There is obviously less overhead with a new thread than forking off a
new process. A thread shares the same pool of objects. A fork has
What does that have to do with Java?

Traditionally, the term "fork" has been used to refer to "creating a new
process" (the traditional way of handling concurrency in Unix code)--the
Unix syscall for this step is literally called "fork." On Unix-based
system, process creation is extremely low overhead, so process-based
parallelism was more common than on Windows where making a new process
is painfully slow.

When I first saw the OP's question, I first thought he was referring to
fork in the process-creation sense, so it's not clear to me offhand if
he is referring to the process-creation fork or Java-framework fork.

The OP explicitly said, "in java [sic]". That clears up that question completely.
 
J

Joshua Cranmer

Joshua said:
When I first saw the OP's question, I first thought he was referring to
fork in the process-creation sense, so it's not clear to me offhand if
he is referring to the process-creation fork or Java-framework fork.

The OP explicitly said, "in java [sic]". That clears up that question completely.

Not necessarily. If he meant the Java framework, I would have expected
him to refer to it as "fork-join" instead of as just plain "fork".
People do ask questions in this newsgroup all the time without naming
things reliably. :)
 
L

Lew

Joshua said:
Lew said:
The OP explicitly said, "in java [sic]". That clears up that question completely.

Not necessarily. If he meant the Java framework, I would have expected
him to refer to it as "fork-join" instead of as just plain "fork".
People do ask questions in this newsgroup all the time without naming
things reliably. :)

You raise a good point.

I suppose I put too much faith in the wording.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top