Check the docs on your JVM to see if it supports multithreading. I'm pretty sure the sun ones do. Java Concurrency In Practice is the place to start for multithreading.
The first part of your question is: is multiprocessing superior to multithreading, from a performance perspective? In a system with robust multithreading support, threads should always be superior to processes, from a performance perspective. There is more isolation between threads (no shared memory, unless explicitly setup via an IPC mechanism), so you might want to go the multiprocess route to keep dangerous threads from stepping on each other.
For data processing, threads should be the best way to go. If threads on your local machine aren't enough, I would skip past a multiprocess solution and go straight to a map-reduce system like Hadoop.
As to why multiprocess apps are mentioned, I think the author wants to be complete. Although a tutorial is not provided, a link to additional documentation is. The big disadvantage of using multiprocessing is that you have to deal with inter process communication. Unlike threads, you can't just share some memory and throw some mutexes around it and call it a day.
From the comments, it appears that there is some confusion about what "multiprocessing" actually is. Threads are constructs that must be created by your code. There are APIs for thread creation and management. Processes, though, can be created by hand on the command line. On a unix box do the following to run four instances (processes) of foo
. Note that the final &
is required.
$ ./foo & ./foo & ./foo & ./foo &
Now if you have an input file, bar
that foo needs to process, use something like split
to break it up into four equal segments, and run foo
on it:
$ ./foo bar.0 > bar.0.out & ./foo bar.1 > bar.1.out & ./foo bar.2 > bar.2.out & ./foo bar.3 > bar.3.out &
Finally, you will need to combine the bar.?.out
files. Running a test like this should give you some feel for whether using heavy-weight processes is a good idea for your application. If you have already built a multi-threaded application, that will probably be just fine. But feel free to run some experiments to see if processes work better. Once you are sure that processes are the way to go, reorganize your code to use ProcessBuilder to spin up the processes yourself.