2

I'm looking into the stacksize parameter for Thread to handle some recursion as described in my other question: How to extend stack size without access to JVM settings?.

The Javadoc says:

On some platforms, specifying a higher value for the stackSize parameter may allow a thread to achieve greater recursion depth before throwing a StackOverflowError. Similarly, specifying a lower value may allow a greater number of threads to exist concurrently without throwing an OutOfMemoryError (or other internal error). The details of the relationship between the value of the stackSize parameter and the maximum recursion depth and concurrency level are platform-dependent. On some platforms, the value of the stackSize parameter may have no effect whatsoever.

Does anyone have some more details? The server running my code has Oracle Java Runtime Environment. Will specifying stack size have effect? I don't have info on the OS (or other system specs), and I can't test myself because I can't submit code year round.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
i'm a girl
  • 308
  • 3
  • 11

1 Answers1

0

Oracle Java Runtime Environment.

That's deprecated.

Will specifying stack size have effect?

It will change the size of each thread's stack, yes.

Will that affect your app? Probably not.

If you run many threads simultaneously (we're talking a couple hundred at least), lowering it may have an effect (specifically, may make your app work whereas without doing that, your app fails with out of memory errors, or the app becomes like molasses because your system doesn't have the RAM).

If you have deep recursive stacks, but not the kind that run forever (due to a bug in your code), upping it may have an effect (specifically, may make your app work whereas without doing that, your app fails with stack overflow errors).

Most java apps have neither, and in that case, whilst the -Xss option works fine, you won't notice. The memory load barely changes. The app continues to work just the same, and as fast.

Does YOUR app fall in one of the two exotic categories? How would we be able to tell without seeing any of the code?

Most apps don't, that's... all there is to say without more details.

If you're just trying to tweak things so it 'runs better', don't. The default settings are default for a reason: Because they work the best for the most cases. You don't tweak defaults unless you have a lot of info, preferably backed up by profiler reports, that tweaking is neccessary. And if the aim is to just generally 'make things run more smoothly', I'd start by replacing the obsolete (highly outdated) JRE you do have. JRE as a concept is gone (java8 is the last that had it, almost a decade old at this point) - just install a JDK.

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72
  • yeah i have the one of the "exotic case" you described, see the question I linked – i'm a girl Nov 29 '20 at 18:20
  • 100000 methods deep is... _a lot_, generally just rewrite recursive methods to a loop, it's generally quite simple. However, 100k is not quite insurmountable, but it does depend on how much space a method invoke uses (java has no TCO, every local variable costs you stack). I'd expect ~80 bytes per invoke, so you'd need an 8MB stack. Give it a shot with that use case and `-Xss10m` - it's hard to know how much you really need. – rzwitserloot Nov 29 '20 at 18:51
  • Can you justify your claim that Oracle Java Runtime Environment is deprecated? The [official source](https://www.oracle.com/java/technologies/javase-jre8-downloads.html) offers up-to-date JRE without any sign of deprecation. – apangin Nov 29 '20 at 19:59
  • @apangin it's right there at the top of that page: license change to a commercial concept. Also, go look for 'JRE9' - which does not exist (and never will). JRE8 is the last, which makes it obvious. – rzwitserloot Nov 29 '20 at 21:56
  • 1
    Oracle has never deprecated JRE so far. Furthermore, it offers commercial support for Oracle JRE up until 2030. A number of other vendors (Red Hat, Azul, Bellsoft, Amazon, etc.) offer free JRE builds and promise to provide updates for at least several years from now. Saying that JRE is deprecated and gone as a concept is a factual error and has nothing to do with the original question. – apangin Nov 29 '20 at 23:01
  • > Oracle has never deprecated JRE - yes they have. Which part of 'there is no JRE9, 10, 11, 12, 13, 14, or 15' is making you think that 'deploy by telling users to download a JRE' is up-to-date advice? "Obsolete" / "Deprecated" does not mean "unsupported". – rzwitserloot Nov 30 '20 at 00:34
  • 1
    I'm afraid, your understanding of "Deprecated" is not quite correct. And your claim that JRE 8 has been deprecated, is not supported by any document. Following your logic, HTTP/1.1 is a deprecated standard, because of existence of HTTP/2 and HTTP/3. In reality, according to IETF, it is neither obsolete nor deprecated. In Java Community, it's JCP that decides what is deprecated and what is not. [According to JCP](https://jcp.org/en/jsr/detail?id=337), Java SE 8 status is *Active*. – apangin Nov 30 '20 at 01:21
  • Regarding *"JRE as a concept is gone (java8 is the last that had it, almost a decade old at this point)"*: [Azul](https://www.azul.com/downloads/zulu-community/?version=java-15-mts&package=jre), [BellSoft](https://bell-sw.com/pages/downloads-embedded/?version=java-15&package=jre), [SAP](https://sap.github.io/SapMachine/), and [Red Hat](https://developers.redhat.com/products/openjdk/download) provide JRE for Java 11 LTS and for the latest Java 15. – apangin Nov 30 '20 at 19:26