本文介绍了多核和Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我刚刚读到服务器如何处理"多个请求,最终遇到了Java多线程和多核cpu.

I was just reading about "How does a server" handles multiple requests and ended up with java multithreading and multiple cores cpu.

在计算机为单核并且同时在Java中有2个线程的日子里,jvm Scheduler将为每个线程分配时间.因此,两个线程永远不会并行运行,而是利用理想的时间(例如,如果某个线程在某些资源上被阻塞).

During the days when the computers were single core and if there are 2 threads in java at the same time then jvm scheduler will take care of giving time to each thread. So, two threads never runs in parallel but makes use of ideal time (e.g. if a thread is blocked on some resource).

但是在Java7中使用多个内核和fork/join框架会是这种情况吗?我的意思是我已经听说过,使用多个内核,我们实际上可以实现并行性.因此,如果我有两个运行的线程,两个cpu内核,并且每个线程都被赋予一个单独的内核(尽管不能保证),那么它们将实际上是并行的,因为jvm调度程序仍会导致时间交织吗?

But is this is case with multiple cores and fork/join framework in java7 ?I mean i have heard that with multiple cores we can actually achieve parallelism.So, if i have two threads running, two cores cpu and each thread is given a separate core (it is not guaranteed though) then will they actually be parallel because jvm scheduler will still lead to time interleaving?

很抱歉,这个问题很愚蠢,但是我真的不确定这个问题.请帮助我理解!!

I am sorry if this question is stupid but i am really not sure on this one. Please help me to understand!!

谢谢!欧尼(Ouney)

Thanks!Ouney

推荐答案

问题是,仍然很难理解实际上有多少个线程,核心等.

The problem is that it is still very hard to understand how many threads, cores, ... are actually available.

我的个人建议:java专家通讯上有几篇文章对这一主题进行了深入探讨.

My personal suggestion: there are several articles on the java specialist newsletter which do a very deep dive into this subject.

例如以下示例: http://www.javaspecialists.eu/archive/Issue135.html

或一个非常新的有关可用处理器数量"的信息: http://www. javaspecialists.eu/archive/Issue220.html

or a very new, on "the number of available processors": http://www.javaspecialists.eu/archive/Issue220.html

这篇关于多核和Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 10:48