Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java program efficiency with different OSs [closed]

I cam across a Java related question recently that was (to paraphrase):

  1. What reasons are there that a Java application might run at a reasonable speed on Operating System A, but sluggishly slow on Operating System B?

  2. What could a programmer do to rectify this problem?

My response would be (I know I'm wrong, but I'll explain my thought process)

(1) an application should run at more or less the same speed on any Operating System with a JVM, since the application is run inside the virtual machine. As long as the VM is designed correctly it shouldn't matter.

(2)uhh..

My question is: what would be a correct answer to this question?


1 Answers

It's all about implementation.

The problem is that the JVM is itself a program which runs natively on the host operating system and is responsible for implementing the Java libraries conforming to the language and library specifications. This implementation requires managing system resources (such as files, threads, sockets, etc.) and each operating system likely has its own "best practices" regarding the management of those resources, which may not necessarily align with the design of the various Java specs. Moreover, the operating system itself implements the interfaces to those system resources and its implementation might not be as robust as on other OSes.

For example, years ago, the Linux thread implementation was considerably less performant than the same POSIX thread APIs on similar UNIX OSes (e.g. Solaris, AIX, etc). So a JVM running on a Linux machine would have the same functionality as one on a Solaris machine but the Linux JVM would be hindered by the (then) less-than-excellent thread implementation on that OS.

like image 165
maerics Avatar answered Jan 25 '26 20:01

maerics



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!