Can anyone explain how java fork-join frameworks allocate tasks to a process开发者_StackOverflow社区or. Can we control it ?
Fork join style frameworks usually use work stealing to schedule task. I.e. every thread has its own scheduler. And new task are enqueued in the same thread as they were created. Only when the queue of one thread's scheduler gets empty, it "steals" task, aka work, from another scheduler.
This is a obviously a simplification.
depends on the OS
on solaris; you can bind processes or LWPs (threads) to a processor set (that can contain 1-n processors/cores)
on linux; you can bind a process to 1-n processors/core via taskset
don't know on windows
so the answer is theoretically yes on solaris, no on the other 2 platforms. For solaris, I think you'd need to call some jni to do the binding on thread creation. Alternatively, if you ensure the threads are started on startup and never get recycled during the life of the vm then you could start the process, wait n seconds then inspect the LWPs using jstack
, find the threads you want and then bind those threads to predefined processor set via the nids (native ids) in the output of jstack
. poolbind
& pooladm
& poolcfg
are the relevant commands you need on solaris.
精彩评论