user9747103
user9747103

Reputation:

Is java multithreading different on different OS?

I'm using java to make a multithreaded program that simulates a restaurant. I'm using the newest Eclipse Java Oxygen to do it. I've tried to run it on both windows 10 and linux mint, always using Eclipse, and it works well on windows but when I try the SAME project on linux it stops. Is there any difference between running a multithreaded program on windows and linux?

Thanks

Upvotes: 0

Views: 379

Answers (2)

Stephen C
Stephen C

Reputation: 718826

Multithreading in Java relies on the OS to schedule native threads. The native thread schedulers are implemented in the kernel by the operating system itself. They are different pieces of code with different behavior. And they are also (possibly) tunable at the system level.

Yes, there are differences than can affect the way that a Java application runs, but it would be difficult to work out what they are ... let alone describe them simply.

It is also possible that the problem you are seeing is due to some other differences between the different execution platforms: there are lots of possibilities. Or it may be due to the way that your application talks to the file system or network or external applications, all of which have differences.


I would suggest you start by using the debugging tools available to you to characterize what is happening when "it stops". Have threads died? Are threads blocked on locks? Etcetera. Then look for specific causes for the specific behavior.

Note that there are two groups of "classic mistake" that people who are new to threads in Java make:

  1. Making unwarranted assumptions about how threads run; e.g. that threads are scheduled fairly, or that they will start and run in an intuitive order.

  2. Inadequate synchronization; e.g. when two or more threads access and/or modify a shared variable or data structure without adequate synchronization. (This can lead to behavior that is unpredictable and highly couter-intuitive.)

When all is said and done, you can write a multi-threaded Java program to work correctly on many platforms. But we can't help you with specific problems unless you describe the problem clearly and show us the relevant code. In a case like this, and MCVE is highly advisable.

Upvotes: 2

Kwright02
Kwright02

Reputation: 777

Because Java is built to be cross-os compatible, there should be no difference in your code no matter the OS. This means if you have an application that uses multiple threads in it, it will work on any Os as long as your actual application works as you want it to. The reason this is the case is that Java converts your Java code in a .java to byteCode in a .class which will be turned into the assembly code for each respective OS. Something that could be stopping your program is Java being outdated, or not installed altogether. If neither is the case then you can look into things like RAM availability and any kind of thread limitations per program in Linux Mint.

Upvotes: 3

Related Questions