I know how to increase the size of the stack for my jvm (I start it with my idea with the -Xss64M flag), but here’s how to make the user of my JAR have an increased stack?

The answer like "let the user increase the stack himself" - does not fit.

General description of the task:
There is an algorithm that recursively bypasses a two-dimensional array and searches for possible areas in which there are different pixels, the fact is that if there are many differences, there is not enough standard stack.

  • You cannot set JVM defaults for a particular JAR ( stackoverflow.com/questions/1018217/… ). Everyone uses workarounds: they slip a script or a wrapper around the user that launches the JVM with the right arguments. Try to describe in more detail what you have for the application and how it starts, can someone offer an alternative. - default locale
  • There is an algorithm that recursively bypasses a two-dimensional array and searches for possible areas in which there are different pixels, the fact is that if there are many differences, there is not enough standard stack. About the script or wrapper can be more? - Vlad Leonidov
  • How do you start all this? How do you set the stack size? How will the user run (is it critical)? - default locale
  • I run it through my idea with the -Xss64M flag, the user will run through jar'ik, quite critically, since even 20% do not match at sizes 800x600 no longer fit into the standard stack) - Vlad Leonidov

2 answers 2

The size of the allocated memory is set at the JVM level and cannot be specified for a specific JAR file.

Accordingly, the task is to start a virtual machine with the specified parameters. For this, the JAR is started by the user not directly, but through an intermediate link, it can be:

  • The startup script is usually OS specific. For example, on Windows, you can give the user a run.bat file that will launch the JAR with the specified settings:

    java -Xss64M -jar MyRunnable.jar 
  • Wrapper is an application specially created for this purpose (JAR or another executable file) that will launch Java with the specified parameters. There are tools that generate a wrapper automatically (for example, Launch4J again for Windows)

A similar question in English about heap size: Can I set Java max heap size for running from a jar file?

    This solution is described here : "It is correct to launch a new Thread with the required stack size and implement the solution in it"

     new Thread(null, new Runnable() { public void run() { new Main().run(); } }, "1", 1 << 23).start(); 

    For stream "1" the stack size will be set to 8Mb.