Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #27946
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2014-04-03 15:10 -0700 |
| References | <ffb65076-f551-432b-b548-303a884abd44@googlegroups.com> <lhjvju$t97$1@dont-email.me> |
| Message-ID | <8692d198-04b4-4b21-915e-b0630cf0c256@googlegroups.com> (permalink) |
| Subject | Re: java thread question |
| From | mcheung63@gmail.com |
Eric Sosman於 2014年4月3日星期四UTC+8下午11時43分54秒寫道: > On 4/3/2014 10:51 AM, mcheung63@gmail.com wrote: > > > Hi All > > > I have write a little program to keep running some threads, i got questions: > > > 1) All threads are running within one process (ps command show me this), but it will eat up all cpu cores, how to explain this? > > > > What needs explanation? That is, what puzzles you? The *purpose* > > of threads is to break up a large task into smaller pieces and let them > > execute in parallel; you *want* those smaller pieces to use whatever > > machine resources they can get. > > > > > 2) If thread will eat multiple cpu core, why wee need fork/join in java? > > > > (I assume you're referring to java.util.concurrent.ForkJoinTask.) > > If your large task subdivides into a million smaller pieces, you don't > > want to try running each piece in a separate thread. A thread is > > "lighter-weight" than a full-scale process, but its weight is non-zero: > > There's a stack, there's other CPU context, there's management overhead > > like schedulers and garbage collectors, ... When you multiply this by > > a million, or even by several thousand, your system will collapse under > > the load, most probably by throwing an OutOfMemoryException. > > > > That's where ForkJoinPool and ForkJoinTask come in. The pool runs > > a manageable number of long-lived threads, and each thread executes many > > ForkJoinTasks in succession. (There are additional intricacies, but > > that's the essence.) You don't have to create, start, shut down, and > > garbage-collect a million threads to get the million sub-tasks done. > > > > -- > > Eric Sosman > > esosman@comcast-dot-net.invalid Thanks, that mean the advantage of fork/join is : I don't need to manage a thread pool by myself.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
java thread question mcheung63@gmail.com - 2014-04-03 07:51 -0700
Re: java thread question Nigel Wade <nmw@ion.le.ac.uk> - 2014-04-03 16:17 +0100
Re: java thread question Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-04-03 11:43 -0400
Re: java thread question mcheung63@gmail.com - 2014-04-03 15:10 -0700
Re: java thread question Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-04-03 19:00 -0400
Re: java thread question mcheung63@gmail.com - 2014-04-04 09:29 -0700
Re: java thread question Roedy Green <see_website@mindprod.com.invalid> - 2014-04-03 17:52 -0700
Re: java thread question mcheung63@gmail.com - 2014-04-04 09:31 -0700
Re: java thread question Roedy Green <see_website@mindprod.com.invalid> - 2014-04-04 09:49 -0700
Re: java thread question mcheung63@gmail.com - 2014-04-05 09:41 -0700
csiph-web