使用Java创建的线程在Windows和Linux上的行为有何不同? [英] Do threads created in Java behave differently on Windows and Linux?

查看:68
本文介绍了使用Java创建的线程在Windows和Linux上的行为有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,Java正在使用操作系统线程(与Erlang相反),这意味着在Windows和Linux上使用Java创建的线程可能表现不同。

As what I know, Java is using operating system threads (in contrast to i.e. Erlang), that means that the threads created with Java on Windows and Linux may behave different.

Windows和Linux上的Java线程有什么不同吗?最大的区别是什么?这可能只是性能上的差异?

Are there any differences on Java threads on Windows and Linux? What is the biggest difference? It's maybe only a difference in performance?

推荐答案

这是一个非常笼统的问题,所以我会给出一般答案。

This is a very general question, so I'll give a general answer.

Java从绿色线程切换到本机线程早期发展。这并不意味着在Windows和Linux上创建的线程的行为会有所不同,因为两个平台都会在各自的JVM实现中使用本机线程。

Java switched from green threads, to native threads early in its development. This does not mean that threads created on Windows and Linux will behave differently as both platforms will utilize native threads in their respective JVM implementations.

每个线程接口都暴露给Java的线程接口操作系统,类似地,通过pthreads和Windows线程进行线程化的本机接口非常相似。

The thread interface exposed to Java by each OS, and similarly the native interfaces to threading via pthreads and Windows threads are very similar.

两个平台上线程的最大区别在于Linux上的所有线程是一种过程形式。 Windows以非常不同的方式处理线程和进程。

The biggest differences with respect to threading on the two platforms are that all threads on Linux are a form of process. Windows treats threads and processes very differently.

根据我的个人经验,Windows上的本机线程稍微更轻,并且在单个进程应用程序中可能表现稍好一些。相应地(也许是无关紧要的),与Linux同行相比,Windows进程是非常重量级的。

In my personal experience, native threads on Windows are slightly more lightweight and may perform slightly better within single process applications. Correspondingly (and perhaps irrelevant), are that Windows processes are extremely heavyweight compared with their Linux counterparts.

这篇关于使用Java创建的线程在Windows和Linux上的行为有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆