对于多核的linux服务器 java多线程与python多线程同时进行io密集型操作 那个的速度会更快一些
我个人的理解是这样的
无论是java还是python它们都是真实的线程,那么也就是调用了操作系统的api创建的了线程 至于说创建的是内核级还是用户级的线程我不得知
如果是用户级线程 那么线程对于cpu不可见 由jvm或者python解释器来控制线程获取cpu资源的权限 所以说对于同一个进程下创建的多个线程,同一时刻只有一个线程获取了cpu的资源,也就是线程只能并发不能并行。那么这里我们常说的Java多线程并行又是怎么一回事 如果多线程只能并发 那么无论多核还是单核 java和python在io密集型应用中性能差不多
如果是内核级线程 同一个进程下同一时刻多个线程可能获得多个cpu的资源 这样就实现了并发 这个就说通了 而python解释器GIL将python线程控制 使得同一时刻只有一个线程有获得cpu资源的权限
上面是我的理解和困惑 还望各位帮忙解答一点点
Due to the limitations of python's own GIL, python multi-threading actually only runs in one core, while java multi-threading can run in multiple cores. Therefore, in a multi-core environment, one process has multiple threads, and Java is properly fast. ah.
Python
作为脚本语言,运行上是解释型的,在速度上是没法和编译型的Java
进行对比的,被Java
It’s impossible to overstate how many streets you can throw away.The two for IO-intensive ones are estimated to be on the same order of magnitude.
For IO intensive, the language in either dimension is not the bottleneck itself at all. The real bottleneck comes from the OS's policy of providing access to IO devices. If we really want to compare the language itself, it is probably limited to the API exposed by the language encapsulation OS, and the coder's proficiency in the API, and that's it.