Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Threads in Java platform dependent?

It is obvious that OS scheduling/ threading algorithms have their impact on Java threads but

can we safely say that Threads are OS/machine dependant?

If this is the case then doesn't it make Java platform dependant?

like image 610
Just_another_developer Avatar asked Nov 05 '12 09:11

Just_another_developer


People also ask

Are threads independent in Java?

Threads in JavaA thread is an independent path of execution within a program. That means, it is a sequence of instructions within a program that can be executed independently of other code.

Are threads dependent?

Threads are parts of a process and so are dependent. Processes have independent data and code segments. A thread shares the data segment, code segment, files etc.

What is platform dependent in Java?

Java is platform-independent but JVM is platform dependent In Java, the main point here is that the JVM depends on the operating system – so if you are running Mac OS X you will have a different JVM than if you are running Windows or some other operating system.

Is Java platform dependent language?

Java is platform-independent because it uses a virtual machine. The Java programming language and all APIs are compiled into bytecodes.


1 Answers

Yes, the details of the scheduling of threads in Java depends on the JVM implementation and (usually) on the OS implementation as well.

But the specifics of that scheduling is also not specified in the Java SE specification, only a selected few ground rules are specified.

This means that as long as the OS specific scheduling is conforming to those ground rules, it is also conforming to the JVM spec.

If your code depends on scheduling specifics that are not specified in the JVM spec, then it depends on implementation details and can not be expected to work everywhere.

That's pretty much the same situation as file I/O: if you hard-code paths and use a fixed directory separator, then you're working outside the spec and can not expect your code to work cross-platform.

Edit: The JVM implementation itself (i.e. the JRE) is platform dependent, of course. It provides the layer that allows pure Java programs to not care about the platform specifics. To achieve this, the JRE has to be paltform specific.

like image 150
Joachim Sauer Avatar answered Sep 18 '22 22:09

Joachim Sauer