Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between -Xss and -XX:ThreadStackSize?

I just want to control the stack size for all of my threads in a Java (groovy) application. For the Hotspot Oracle VM, I know that there are two parameters doing that (-Xss and XX:ThreadStackSize).

Which is the preferred one? Is there any difference between them? Regarding Open JDK 7 someone asked on the mailing list, stating that -Xss is the same for the Hotpot VM as -XX:ThreadStackSize.

The point is, that I am measuring how many threads can be started on my system. My groovy script which does this looks like:

int count = 0

def printCountThreads = {
     println("XXX There were started $count threads.")
}

try {
    while(true){
            new Thread({Thread.sleep(Integer.MAX_VALUE)}).start()
            count++
            if(count % 1000 == 0){
                    printCountThreads()
            }
    }
} catch (Throwable e){
    printCountThreads()
    throw e
}

Interestingly enough I just get a reduced number of of threads using -XX:ThreadStackSize. I am starting the groovy application with and with different content in the environment variable JAVA_OPTS.

groovy countmax-threads.groovy

When I set JAVA_OPTS to -XX:ThreadStackSize=2m, I get about 1000 started threads until the memory is consumed. But, when I use JAVA_OPTS='-Xss2m', I get about 32000 threads until the expected error arises. So it seems that -Xss does not work at all.

I am using

java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

on a Ubuntu 14.04 64 bit machine with four hardware threads and about 8 GB of RAM.

UPDATE:

I reverified this on my Windows 7 64 bit machine and another JDK:

java version "1.8.0_20" Java(TM) SE Runtime Environment (build 1.8.0_20-b26) Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

and there -Xss and -XX:ThreadStackSize work as expected (as some answers pointed out). So I suppose it is a Linux specific problem or even a bug in the JDK version 1.8.05.

like image 638
user2078148 Avatar asked Feb 27 '15 14:02

user2078148


People also ask

What is the difference between double and single quotation marks?

General Usage Rules In America, Canada, Australia and New Zealand, the general rule is that double quotes are used to denote direct speech. Single quotes are used to enclose a quote within a quote, a quote within a headline, or a title within a quote.

What is the difference between (;) and (:)?

Colons and semicolons are two types of punctuation. Colons (:) are used in sentences to show that something is following, like a quotation, example, or list. Semicolons (;) are used to join two independent clauses, or two complete thoughts that could stand alone as complete sentences.

What's the difference between and ≥?

Greater than or equal to sign: ≥ This is because ≥ does not denote a strict inequality. This is the only difference between ">" and "≥".

What's the difference between apostrophe and quotation marks?

But I bet you're curious about how they're different, why else would you be here? The main difference between the two is: Quotation marks are used to report speech. An apostrophe is used for making contractions and possession.


1 Answers

-Xss is an alias for -XX:ThreadStackSize both for OpenJDK and Oracle JDK.

Though they parse arguments differently:
-Xss may accept a number with K, M or G suffix;
-XX:ThreadStackSize= expects an integer (without suffix) - the stack size in kilobytes.

like image 147
apangin Avatar answered Sep 18 '22 15:09

apangin