Optimizing thread stack size

There seems to be general confusion around the actual behaviour of the -Xss option.
I need to optimise the thread stack size on Windows 2000 server running JVM 1.4.2 (07).
1. What is the actual minimum stack size for this JVM ? 1k, 6k, 64k ?
2. Do there exist any mechanism to measure the maximum value actually utilized by a particular application ?
The goal is simply to allocate the appropriate amount of stack space instead of guessing a safe value.

The default stack size is 256K on UNIX and on 32-bit Windows operating systems. To set Stack size
java -XX:NewSize=128m -XX:MaxNewSize=128m -XX:SurvivorRatio=8 -Xms512m -Xmx512m
1. Setting the New generation heap size
-XX:NewSize
Use this option to set the New generation Java heap size. Set this value to a multiple of 1024 that is greater than 1MB. As a general rule, set -XX:NewSize to be one-fourth the size of the maximum heap size. Increase the value of this option for larger numbers of short-lived objects.
Be sure to increase the New generation as you increase the number of processors. Memory allocation can be parallel, but garbage collection is not parallel.
2. Setting the maximum New generation heap size
-XX:MaxNewSize
Use this option to set the maximum New generation Java heap size. Set this value to a multiple of 1024 that is greater than 1MB.
3. Setting New heap size ratios
-XX:SurvivorRatio
The New generation area is divided into three sub-areas: Eden, and two survivor spaces that are equal in size.
Use the -XX:SurvivorRatio=X option to configure the ratio of the Eden/survivor space size. Try setting this value to 8, and then monitor your garbage collection.
4. Setting minimum heap size
-Xms
Use this option to set the minimum size of the memory allocation pool. Set this value to a multiple of 1024 that is greater than 1MB. As a general rule, set minimum heap size (-Xms) equal to the maximum heap size (-Xmx) to minimize garbage collections.
5. Setting maximum heap size
-Xmx
Use this option to set the maximum Java heap size. Set this value to a multiple of 1024 that is greater than 1MB.
Hope these are the options you are looking for.

Similar Messages

  • Thread stack size problem

    Hi all,
    I am having a multithreaded application and the threads are created with 256 KB thread stack size.
    This application was developed in windows(32 bit) now ported to Solaris 8.
    The same was failed while running because of stack overflow and then the thread stack size is increased to 257 KB then the application is working fine.
    Please anybody suggest me how the same application is working fine in windows with lesser thread stack size?
    Please also suggest me any tool which can be used to get the thread stack details while running the application.
    Regards,
    Velan.R.S

    Hello Farhan
    We had similar issues and we tackled it in a few ways. First you may want to track down what type of memory issues you are hitting, permgen verse heap
    Simple Tomcat updates I would look into
    set your inital memory pool to something like 256 MB
    Up your max to 2 or 3 GB
    if you are having permgen issues i would set the following in your tomcat java options
    -Xrs
    -XX:MaxPermSize=512M
    -XX:+CMSClassUnloadingEnabled
    -XX:+UseConcMarkSweepGC
    -XX:+CMSPermGenSweepingEnabled
    -Djava.awt.headless=true
    I would also look into increasing your treads and adding compression to your 8080 listener
    Tomcat Vertical Scale
    Once you have done the simple tomcat updates if you still have issues you may want to add more tomcat instances and use use a proxy server to load balance them. You can use Apache with mod_proxy or mod_jk. or even a more enterprise solution with an appliance like BigIP f5 or Cisco CSS.
    I would really recommend front your tomcat(s) with Apache and doing a split deploy. Then fronting your apache servers with an appliance load balancer. James Rapp has a great article on how to do this. 

  • Stack size for native thread attaching to JVM

    All:
    I have a native thread (see below, FailoverCallbackThread) that attaches to the JVM and does a Java call through JNI. The stack size for the native thread is 256KB.
    at psiUserStackBangNow+112()@0x20000000007a96d0
    at psiGuessUserStackBounds+320()@0x20000000007a8940
    at psiGuessStackBounds+48()@0x20000000007a8f60
    at psiGetPlatformStackInfo+336()@0x20000000007a9110
    at psiGetStackInfo+160()@0x20000000007a8b40
    at psSetupStackInfo+48()@0x20000000007a5e00
    at vmtiAttachToVMThread+208()@0x20000000007c88b0
    at tsAttachCurrentThread+896()@0x20000000007ca500
    at attachThread+304()@0x2000000000751940
    at genericACFConnectionCallback+400(JdbcOdbc.c:4624)@0x104b1bc10
    at FailoverCallbackThread+512(vocctx.cpp:688)@0x104b8ddc0
    at start_thread+352()@0x20000000001457f0
    at __clone2+208()@0x200000000030b9f0
    This causes stack overflow in Oracle JRockit JVM. (It does not cause overflow with Oracle Sun JDK.) Is there a recommended stack size for this use case for JRockit? Is there a way to compute it roughly?
    Platform Itanium 64 (linux)]
    java version "1.5.0_06"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
    BEA JRockit(R) (build R26.4.0-63-63688-1.5.0_06-20060626-2259-linux-ia64, )
    mp

    How do I found default heap size, stack size for the
    thread, number of threads per jvm/process supported ?The threads is OS, OS install and jvm version specific. That information is also not useful. If you create the maximum number of threads that your application can create you will run out of memory. Threads require memory. And it is unlikely to run very well either.
    The default heap size and stack size are documented in the javadocs that explain the tools that come with the sun jdk.
    and how the above things will vary for each OS and how
    do I found ? Threads vary by OS, and OS install. The others do not (at least not with the sun jvm.)
    If I get "OutOfMemoryError: Unable to create new native thread" Most of the time it indicates a design problem in your code. At the very lease, you should consider using a thread pool instead.
    I found in one forum, in linux you can create maximum
    of 894 threads. Is it true ?Seems high since in linux each thread is a new process, but it could be.

  • Cannot increase the stack size

    Hi,
    We have a program which gives a StackOverflowError. Trying the increase the stack size using command line options does not work. A simple program shows that the stack is the same size, whatever option we set.
    This is the program:
    class StackOverflowTest
    public static int counter = 0;
    public static void main(String[] a)
    try {
    sub();
    } catch (StackOverflowError e)
    System.out.println("recursive calls: "+counter);
    public static void sub()
    counter++;
    sub();
    We tried several -Xss (and -Xoss) settings: 600K, 2048K, 4M but got the same recursion deep: 16683 (with Eclipse), or 16689 (command line).
    We used Windows XP.
    Do you have any clue?
    Many thanks,
    Zsolt

    Oh good, they seem to have broken the forum formatting again.
    ====================================================================================================================
    Bug ID:     4362291     Stack size argument ignored (-Xss and -ss)
    ====================================================================================================================
    public class StackOverflowTest {
        public static int counter = 0;
        public static final void main(String[] a) {
            new Thread(new Runnable() {
                public void run() {
                    try {
                        sub();
                    } catch (StackOverflowError e) {
                        System.out.println("recursive calls: "+counter);
            }).start();
        public static final void sub() {
         counter++;
         sub();
    /code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Default stack size vs. -Xss option

    Hi,
    What the default stack size?
    That is, if you use the -Xss<size> option, it will set the stack
    size to <size>, but what is the default. I've searched and only
    found one posting that says it is 256k.
    http://forum.java.sun.com/thread.jsp?forum=256&thread=40530
    Is that correct? Since this is a JVM option, is it platform
    dependant? In that case, what would it be on Win2k and Solaris?
    We are serializing graph objects and getting a StackOverflowError
    on occassion. There is a well known bug about this:
    http://developer.java.sun.com/developer/bugParade/bugs/4152790.html
    Thanks.
    --- Patrick

    Hi,
    It depends on version and OS.
    In Solaris there is in addition the OS restriction in ulimit
    or maxssiz in HP.
    hurricane% ulimit -a
    time(seconds) unlimited
    file(blocks) unlimited
    data(kbytes) unlimited
    stack(kbytes) 8192
    coredump(blocks) unlimited
    nofiles(descriptors) 4096
    vmemory(kbytes) unlimited
    Workaround - Use "ulimit -s 2048" in bash shell or "limit stacksize 2048" in tcsh to limit the initial thread stack to 2 MB.
    http://java.sun.com/docs/hotspot/VMOptions.html
    Check the link for the Solaris defaults.

  • RangeError: Maximum call stack size exceeded

    Dear all,
    we are executing and EDGE project in a Samsung SmartTV.  In more powerful models (more memory and cpu) the execution is correct. but in some old TV models we receive the following  message:
    File:   file://c/........../EDGE_006/edge_includes/edge.2.0.1.min.js
    Line No:  135
    Error Detail: RangeError: Maximum call stack size exceeded.
    It seems that this happens depending on the complexity of the EDGE project, as for some simple projects it works.
    we would like to adjust our EDGE project for this less powerful models modifiying animations and simplifying complexity, but we dont know where to start (which animations to remove, etc.)
    Or if there are some parameters in the edge API to adjust in order to increase performance in low memory browsers.
    Thank you in advance,
    Luis

    sunil-online wrote:
    > I am calling an external DLL and running it in the UI thread. How much
    > stack space is available when they are on separate threads or on the
    > UI thread?
    >
    > The problem is that I am getting seemingly random crashes while
    > running this VI and after I quit labview after stopping and uninit-ing
    > my DLL.
    Unless you know this DLL is using exceedingly lots of stack (at least
    several dozens of MB) for whatever obscure reasons it is very unlikely
    that running out of stack space is causing your problem. More likely
    either the DLL does something nasty to a data pointer passed in to it or
    you made an error in setting up the call to the DLL.
    For instace if the DLL expects strings or array pointers to be passed in
    they need to
    be allocated by the caller (here LabVIEW) and you need to
    tell LabVIEW to do that in the diagram code.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Call Stack Size

    Is there a way to increase the call stack size of LabVIEW or to know
    when it has been exceeded?
    Thanks.

    sunil-online wrote:
    > I am calling an external DLL and running it in the UI thread. How much
    > stack space is available when they are on separate threads or on the
    > UI thread?
    >
    > The problem is that I am getting seemingly random crashes while
    > running this VI and after I quit labview after stopping and uninit-ing
    > my DLL.
    Unless you know this DLL is using exceedingly lots of stack (at least
    several dozens of MB) for whatever obscure reasons it is very unlikely
    that running out of stack space is causing your problem. More likely
    either the DLL does something nasty to a data pointer passed in to it or
    you made an error in setting up the call to the DLL.
    For instace if the DLL expects strings or array pointers to be passed in
    they need to
    be allocated by the caller (here LabVIEW) and you need to
    tell LabVIEW to do that in the diagram code.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Error stack size

    Hi,
    i have build a package framework which in exceptional situations uses an encapsulated raise_application_error method with the
    -add to error stack- option. In combination with
    -speaking- messages it seems as if i am now running against the error stack size border. What i see is that the primarily generated errors are lost.
    Is it possible (and recommended) to increase the size and does anyone now how to do this ? (I still have to use 8.1.7)
    Thanks in advance,
    Bjoern

    First of all: you should mention it when you cross-post, to prevent people from wasting their time providing an answer already given in the other site.
    https://community.jboss.org/thread/223626
    Doing a google for "The stack size specified is too small, Specify at least 160k" gives plenty of reason to believe it is not really a 'problem', but simply a requirement of the JVM; how and why can only be answered by the developers of said JVM, you're not going to find them here because this is a user to user forum. And this isn't any different under Java 7.
    So other than downgrading, I don't see how you're going to make any impact. I would do the Google yourself, collect the search results that all indicate that the startup scripts are adjusted to the wishes of the JVM and present that to the vendor to shut them up. Anything more - well good luck getting an official statement from Oracle.

  • Help! VerifyError: stack size too large??

    I seem to have a class file with which the class file verifier has a complaint:
    D:\test\out>java Probe
    Exception in thread "main" java.lang.VerifyError: (class: Probe, method: main signature: ([Ljava/lang/String;)V) Stack size too large
    Can anybody point me towards documentation about what the algorithm is or should be to calculate the correct stack size. Or documentation on the message?
    I assume the meaning of the message is that the operand stack size is larger than used by the code for the static method main.  However, I haven't a clue as to the algorithm I should verify the size against. 
    Thanks for any help suggestions                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Thanks for the suggestion. I am running a modified Class file and have read the jvm spec. I was hoping somebody would have a suggestion as to what the error message actually means...
    For example does this mean that the declared size of the operand stack is greater than that required by the code? Or perhaps that the declared size is too large for the code?
    The actual method is quite small (on the order of 500 instructions).
    I know that the jvm has a requirment that the operand stack have the same size along all control paths (loops, gotos, etc) to a specific instruction. I don't know what error the verifyer would give if this was the problem.
    Is there any documentation anywhere the verifier's error messages?
    Thanks for any help you can give.

  • Setting JVM stack size

    Hi,
    I have a Java Application that is packed in a jar file, and that I start double clicking the jar file in the Windows desktop. My question is: How can I say to the JVM that runs with a Stack Size greater of usual, I want 2MB?.
    Thanks in advance!!
    Salvador Huertas.

    You cannot alter the stack of the primordial thread that is started with the java command (the thread is already started before the size is read.) You can alter the stack size of subsequent threads that are started - the non-primordial threads.
    See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4362291
    So, you can't change the "JMV stack size" - you can change the size of additional threads.

  • Change the default stack size in the java.exe file

    Does anyone know how to change the default stack size of the jvm?
    I'm having problems with my stack. Is there anyway I can change it. I found a tool editbin.exe which is shipped with Visual c++, however I don't have the tool.
    Thanks,
    William

    I am using JNI to connect java with a C++ application.
    When calling the C++ appliction, STACK_OVERFLOW
    happends. I tried java -Xss<size> to increase the
    stack size, but failed.This has nothing to do with the above question.
    Does anyone knows why?Probably because the java parameter specifies the java stack size and not the C++ stack size.

  • How can I increase the hard limit of the stack size?

    Hi,
    My process gives an error of segmentation fault (SIGSEGV) that is caused because the stack limit is reached. I have a doubt about how to increase the stack size. I have tried change it with "ulimit - hard" but this size is 65532kb, and is very low for my process. How can I increase the hard limit?
    Thanks.

    When last I checked, the kernel had a fixed stack size limit.
    Do you have the source code to this application? If so, [see this Tiger stack size article|http://homepage.mac.com/eric.c/hpc/contents/documentation/How%20to%20in crease%20the%20stack%20size%20on%20Mac%20OS%20X.pdf], and specifically have a look at the +ld -stack_size+ mechanism; rebuild the code with a bigger limit.
    Entirely FWIW, this question would be more typical over in the developer forums or maybe in the Unix forum if you don't have Apple developer access. Better audience for application development and for software-related questions over there.

  • Why ulimit  fails for stack size in Sol 10 update 11 with project settings?

    Hi,
    The following command fails on Solaris 10 update 11 platform. It works fine with update 10. Something has changed in update 11. Any ideas?
    ulimit -Ss 1 (or any number for that matter)
    /bin/ksh: ulimit: exceeds allowable limit
    We have the following setting in project as well.
    process.max-stack-size=(basic,137988707188736,deny)
    process.max-stack-size=(priv,137988707188736,deny)
    Thanks for your help in advance.
    Samy

    Here are the values from the project command if you anyone is wondering
    update 10
    ======
    cat /etc/release
    Oracle Solaris 10 8/11 s10x_u10wos_17b X86
    Copyright (c) 1983, 2011, Oracle and/or its affiliates. All rights reserved.
    Assembled 23 August 2011
    prctl -n process.max-stack-size $$
    process: 10189: /bin/ksh -i
    NAME PRIVILEGE VALUE FLAG ACTION RECIPIENT
    process.max-stack-size
    privileged 125TB max deny -
    system 125TB max deny -
    update 11
    ======
    cat /etc/release
    Oracle Solaris 10 1/13 s10x_u11wos_24a X86
    Copyright (c) 1983, 2013, Oracle and/or its affiliates. All rights reserved.
    Assembled 17 January 2013
    prctl -n process.max-stack-size $$
    process: 24776: /bin/ksh -i
    NAME PRIVILEGE VALUE FLAG ACTION RECIPIENT
    process.max-stack-size
    basic 125TB - deny 24776
    privileged 125TB - deny -
    system 125TB max deny -

  • Need of changing the default stack size permanently as reported by ulimit -

    Hi All,
    In order to install proper 11gr2 on solaris 10 I need to make change of stack size permanently.
    My current ulimit -s is 8192 but according to the oracle 11g installation docs (Configure Shell Limits) they recommend you change the value reported by ulimit -s to be 32k (or 32768).
    I can change this value usiing "ulimit -s 32768" but after reboot of sever this value alwayes change back to old value(8192).
    I tried to do that in /etc/projects but not able to make this permanent, How to make stak size permanently in solaris 10.
    I am on ...
    Oracle Solaris 10 8/11 s10s_u10wos_17b SPARC

    Hi;
    I suggest please review:
    http://serverfault.com/questions/21417/how-to-set-ulimits-in-solaris-10
    It seems that parameter will lost after server reboot. SoThe above settings are not permanent and will be lost after the reboot of the server. To make the changes permanent you need to set this in the respective user profile file. (For ex : .bash_profile on linux)
    Please review:
    Connecting Using: sqlplus "/ as sysdba" Fails with ORA-12547 with Lower Ulimit Setting [ID 878375.1]
    Regard
    Helios

  • Thread Pool Size

    What can be the maximum thread pool size used in java.
    What happens if i put up a thread pool size in range of 10k or 20k.
    how does affect system performance ???
    Its quite urgent for me to know. Can someone help out ???
    Regards
    Hrushi

    I'd say it depends on the machine you are running on, amount of memory and number of CPUs and such, not on Java itself. And with that many threads your implementation better be darn good in order not to be the bottleneck...

Maybe you are looking for