2

We are working on a (big) system that runs as a Java Web Start application. Thus, the user downloads the JNLP file, and runs it on his or her computer.

We have had issues with some users claiming that the application hangs when they open a few windows. We have made some tests and the reason is clear and repeatable:

  • If a user opens the JNLP file using the 32 bit JVM, the max memory sticks to 256 MB, and once this threshold is surpassed, the application goes 0% free memory and hangs.
  • If the same user opens the same JNLP file using the 64 bit JVM, the max memory starts at 256 MB, but as the system needs more memory, the JVM reserves and uses it freely, up to more than 1 GB if needed.

We made several tests and the situation is always the same.

Is there any way for the 32 bit JVM to behave exactly as the 64 bit? I know we can set a max heap size, but the final user may have 1GB, 2GB or 3GB of free memory, and we would like him or her to be able to use them if needed, which is exactly what happens with the 64 bit.

We are using Java 8, update 201.

The application's memory needs depend on how many windows do you open. For a normal use, 256MB-512MB would be more than enough, but some users would benefit from being able to open 7-10 screens, and that could go up to 800MB-1GB of RAM.

Faliorn
  • 1,117
  • 1
  • 11
  • 19
  • Unrelated to your question, but necessary: I strongly recommend finding another deployment strategy beyond Java Web Start as it is deprecated and being violently and frustratingly removed from production by Oracle: https://stackoverflow.com/questions/46904795/java-web-start-support-in-java-9-and-beyond/47168855#47168855 – ryvantage Feb 14 '19 at 15:26
  • We're working on that, but as you may have suspected, it's the only way to work as of today. It's about redoing 5K screens, you know. – Faliorn Feb 14 '19 at 15:27
  • Yes, most of my client applications are deployed via JWS so I'm in the same boat of needing to re-platform my apps or risk losing a large portion of my clients/income – ryvantage Feb 14 '19 at 15:28

1 Answers1

4

You should specify the memory required by the application in the JNLP file using max-heap-size parameter and don't depend on the client system:

<java version="1.8" initial-heap-size="256m" max-heap-size="1024m"/>

In most cases default JVM heap is at most 25% of the available system memory. If some of the users have only 1GB RAM then they will never get more than 256 MB heap if you don't specify it yourself.

Do note that since you are supporting 32 bit JVMs you can't go over 2 GB.

Karol Dowbecki
  • 38,744
  • 9
  • 58
  • 89
  • We tried that, but we have found that, in this case, if the user has less than 1GB of free RAM, the application wouldn't even start and fail. Therefore, we cannot use this approach. – Faliorn Feb 14 '19 at 15:19
  • Set the initial requirement to something small which may be supported by all clients, e.g. 64MB. And set the maximum to something which the clients should support like 512MB. We do not know the max heap requirement of your application. You may need to optimize or use different start JNLP files for different systems. There exists no "one requirement fits all systems". – Konrad Feb 14 '19 at 15:36
  • @Konrad That would be nice... if it worked :(. Somehow, if the OS cannot reserve the maximum heap requested, the application wouldn't run at all... – Faliorn Feb 14 '19 at 15:46
  • @Konrad Added memory requirements in the question. However, my main point in this question is: Why (on Earth) 32 bit JVM behaves differently than 64 bit? – Faliorn Feb 14 '19 at 15:50
  • 3
    @Faliorn because by default JVM configures heap size dynamically based on available system memory and 32 bit systems can't physically have more than 4 GB of memory which means that 32 bit JVM won't get more than 1 GB heap when running on defaults. – Karol Dowbecki Feb 14 '19 at 16:02
  • They do not behave different. They are just limited. – Konrad Feb 14 '19 at 16:21
  • I marked the answer as correct for that's the way to go. What's confusing to me is that, with the same computer and the same free memory (less than 2GB), 32 bit JVM sticks to 256MB and 64 bit goes beyond 1GB. It seems that the default "max-heap-size" is calculated differently, even in the same computer with the same situation. – Faliorn Feb 14 '19 at 16:25
  • 1
    It's not only the space of the OS. The 64 bit version can map the space to a wider address range. This result in easier layout of the heap compared to the smaller 32 bit address range. The heap is more fragmented on 32 bit. – Konrad Feb 14 '19 at 16:28
  • 1
    A 32 bit program (e.g. a JVM) running on 64 bit system will have limited memory (and potentially a per-process limit depending on the OS). That's why 64 bit architecture was introduced, to allow for more memory to be addressed. – Karol Dowbecki Feb 14 '19 at 16:28