英文:
Can several Java threads be scheduled to use parallel stream and run on a different processor core?
问题
我正在运行在几个处理器核心上的Windows系统(物理和逻辑核心都有)。就我对Java线程的理解而言,线程作为轻量级进程运行,共享JVM进程的内存(堆和全局区域)。每个并发运行的线程都有一个单独的不可共享的堆栈,并且我们分配一个方法作为线程执行的一部分。当我们管理共享资源(内存、文件句柄、数据库连接等)的同步时,我们具有具有独立调用数据栈的不同代码执行。现在,第一个问题是,我是否有控制权来在不同的处理器核心上运行线程(如果可用)。如果没有,那么我可能会未充分利用处理器的能力,使一个处理器核心负载过重,而其他处理器核心则未被充分利用。这是否可以通过javac的编译标志以及随后的java JVM标志来控制呢?
下一个问题与Java并行流有关。由于我有大量的输入和输出流操作,这些操作大多彼此独立,无论是内容还是执行的时间顺序都是如此。这需要使用并行流,在不同的处理器核心上进行理想的调度,以获得更快的执行速度。有什么建议/指针吗?
英文:
I am having Windows system running on several processor cores (physical as well as logical). As far as my understanding goes for Java threads, threads run as light-weight processes sharing the memory (heap and global area) of the JVM process. Each concurrently running thread has a separate non-shareable stack and we assign a method to be run as part of the thread execution. While we manage synchronization for shared resources (memory, file handle, database connection etc), we have different code execution with separate call stack of data. Now, first question is, do I have a control to run threads on different processor cores,if available. If not, then I could be under-utilizing my processor capacity having one processor core heavily loaded and other processor cores under utilized. Can that be controlled through compilation flags of javac and subsequently java jvm flags?
Next part of question is regarding java parallel stream. Since I have heavy duty input and output streaming operations, mostly independent of each other, in terms of content as well as chronology of executions. This demands to use parallel stream, ideally scheduled on different processor core to gain execution speed. Any suggestions/pointers?
专注分享java语言的经验与见解,让所有开发者获益!
评论