Monitor thread stacks in JVM

Hi,
I've a problem with my app, when my server runs for a long time, the memory used by the java process increases.
I investigate this : the use of the heap seems to be good (no memory leak), i've used pmap for retreiving the use of memory by my process and i've seen that the number of range of memory reserved for [anon] increases (about 520K each times).
I think that it is thread stack reserved but not freed.
My question is : How can i link a memory address reservation with a thread (if it's possible) ??
I use a JDK 1.5.0_10 un der RedHat Enterprise 3 Updt 4.
Thanks

pls tell me thread running in jvm or operating systemIIRC, unless you are using a very old JVM (e.g. pre 1.2) or are explicitly specifying green threads (which I believe was still possible even in 1.2?) then all threading using native threads. As mentioned above, the mapping between Java thread objects and the native threads is is highly dependent on the OS (especially when it comes to thread priority).
This document goes into much more detail: http://java.sun.com/docs/hotspot/threads/threads.html
- N

Similar Messages

  • 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.

  • Monitoring threading

    Hello,
    I was looking at the little JVMTI documentation I could find. Any pointers to good docs? I had to go mostly with the API style reference..
    As to my needs, I would like to monitor thread scheduling in real-time. So I could record which thread is running at which point and for how long. Is this possible with JVM TI or some other API? I see there are event functions for thread start and end. I could possibly hook those and add an event listener to each thread to record when it starts execution. I just dont know what event to use to record execution start after the switch, since none really seem good for the job. Naturally, I am interested in minimal overhead. Ideas?
    Also as a second note, I am also interested in monitoring resource usage, such as file access, network activity, etc... much like probes in systemtap (http://sourceware.org/systemtap/) and similar tools. Is there some way to do this effectively in Java? I realize it may be more difficult as the VM is not quite the OS kernel here..?
    Any pointers and other help would be great.
    thanks!

    Why don't you have a common data object which is
    passed to all the threads and the thread monitor
    class? In such a approach it will be easy for the
    threads to communicate and also if you need to
    synchronize them you can use wait / notify.Nah, I wouldn't pool the data unless I needed to. That way deadlock madness lies. If the data is specific to a thread, keep it in the thread's class.

  • Thread running in jvm or os

    pls tell me thread running in jvm or operating system

    pls tell me thread running in jvm or operating systemIIRC, unless you are using a very old JVM (e.g. pre 1.2) or are explicitly specifying green threads (which I believe was still possible even in 1.2?) then all threading using native threads. As mentioned above, the mapping between Java thread objects and the native threads is is highly dependent on the OS (especially when it comes to thread priority).
    This document goes into much more detail: http://java.sun.com/docs/hotspot/threads/threads.html
    - N

  • Monitoring thread usage for ExecutorService objects

    Is there a way to find out how many active threads there are running in an ExecutorService? I am using a fixed thread pool (Executors.getFixedThreadPool()) and I want to monitor thread count in order to see if the pool size I chose is too small.

    The number of "active threads" is an idea which is really only relevant to those ExecutorServices that are ThreadPoolExecutors. (Which does tend to be most of them.)
    You could replace Executors.newFixedThreadPool(int) with its implementation, to get a ThreadPoolExecutor, which includes a method getActiveCount().

  • 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. 

  • Cannot stop memory monitor thread

    Hi All,
    I am getting the following error intermittently in a dataflow which has degree of parallelism = 8.
    22943 0 SYS-170111 27/11/2009 12:22:05 |SubDataflow DF_Conform_ISI_Person_Match_Prep_1_9
    22943 0 SYS-170111 27/11/2009 12:22:05 Cannot stop memory monitor thread: <RWThreadImp::terminate - No thread is active within the runnable>
    Any ideas as to the cause ?
    Thanks,
    Eric Jones.

    We are having the same issue.
    According to ADAPT00890818, this issue should be resolved in 12.0.0. We are currently running with version 12.2.2.3.
    Please advice.

  • SYS-170111 - Cannot stop memory monitor thread: RWThreadImp::terminate -

    Hi Experts,
                  WE have this warning in pretty much every job in production. But the warnings are not specific to certain jobs they might occur one day and not the other day.
    Cannot stop memory monitor thread: <RWThreadImp::terminate - No thread is active within the runnable>.
    I know looking at the release notes this issue was fixed in 3.0 (12.0.0), we are using 3.2 (12.2.0) and having the same issues. The job server is on a linux 64 bit. I have not seen this issue in any of our windows job server. Is this bug specific to linux or is there a resolution for this.
    Appreciate your help in advance.
    Thanks
    AJ
    Edited by: alangilbi on Sep 28, 2011 5:17 PM

    Hi, AJ.
    As can be seen in the KBA 1455412 this is a known behavior.
    "As a result of fixing the problem identified in ADAPT 00890818 in release 12.0.0.0, this message is displayed by design. If there is really a problem in stopping the memory monitor thread an exception is thrown and an error message is logged.
    Background:
    In the memory monitor's shutdown logic, once it tells the monitor thread to shutdown it waits for the thread to terminate but only for 10 seconds. It could be that at this same time the wait expired when the thread actually terminates. So when this happens in the shutdown logic we force terminate the thread. Since there is no active thread anymore the terminate call throws an exception and then we catch it and then throws the error for the job."
    You can just ignore this warning.
    Leo.

  • 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.

  • Mechanism for monitor java application or JVM

    Ladies & Gentleman,
    I develop Java application under Windows 2000 datacenter. For gurantee to capture all of abnormal situation of java application and also JVM, I need to know how to capture the situation. Do any other tools to do these things? I am very appreciated if you could tell me.

    You don't exactly need any specific tools to just capture exceptions, that can easily be done by wrapping the program you want to monitor with your own main() method and adding some shutdown hooks...
    But it would be nice to know what you want to do once it happens....
    Regardless of which, here's an example of that wrap...
    import java.lang.reflect.*;
    public class Watch extends Thread
         public void run()
              System.out.println("VM is closing down");
         public static void main(String[] args) throws Exception
              if (args.length == 0)
                   System.out.println("You must supply the name of the class to start with.");
                   System.exit(1);
              Runtime.getRuntime().addShutdownHook(new Watch());
              try
                   Class theClass = Class.forName(args[0]);
                   Method theMethod = theClass.getDeclaredMethod("main", new Class[]{String[].class});
                   String[] theNewArray = new String[args.length - 1];
                   System.arraycopy(args, 1, theNewArray, 0, theNewArray.length);
                   System.out.println("Starting program with class "+args[0]+"...");
                   theMethod.invoke(null, new Object[]{theNewArray});
                   System.out.println("Program is done running.");
              catch (ClassNotFoundException cnfe)
                   System.out.println("No such class: '"+args[0]+"'");               
              catch (NoSuchMethodException nsme)
                   System.out.println("The class "+args[0]+" has no main method.");
              catch (SecurityException se)
                   System.out.println("Can't start: "+se.getMessage());
              catch (IllegalAccessException iae)
                   System.out.println("Can't invoke main method in class "+args[0]+": "+iae.getMessage());
              catch (Exception ite)
                   System.out.println("Exception occurred when running class "+args[0]+": "+ite.getMessage());
    }You can easily just swap those System.out's for something else.
    However, if you mean watching the process from outside the VM, then you need something else, I suppose.
    /F

  • Multiple java threads in a JVM created by the invocation interface

    Hi,
    I have a certain application APP that calls functions of a C library. One of these functions creates a JVM through the invocation interface. In the JVM I create some other threads and a Swing GUI. From the java "main" thread as well as the other threads (including the Swing event dispatcher thread) I need to call dll functions through native java methods. The latter indirectly (through another dll) invoke functions of an API of application APP.
    I have problems when making calls from the java threads to the java native library. In some cases everything works well i.e., I'm able to make calls to the java native library from both the "main" java thread and the other threads. In other cases a crash occurs when attempting to access the native library from any threads but the "main" thread.
    Can anyone help me on this? Is there any requirement that only the main java thread makes callbacks to C code?
    Thanks.

    > why later sets of java application is taking longer?
    Probably because of CPU usage.  But could be memory.
    >Can I do something here so that later sets of apps also completes in 3 mins
    You tune the task, the complete task, to the box.  That means you must understand in detail what is taking time and then architect that to make the best use of the available CPUs and memory (and other resources as used by the task.)

  • Potential Thread Problem with JVM (1.4.2_05)

    This junit test fails on 1.4.2_05 (running on Windows XP), is there a problem with the code or the JVM?
    public class BadJVMTest extends junit.framework.TestCase {
      static byte[] b = new byte[] { -1, 1 };
      public int m2(int offset) {
        while (true) {
          if (b[offset] >= 0)
            return offset + 1;
          offset++;
      class Inner {
        int fOffset = 0;
        public void m1() {
          fOffset = m2(fOffset);
          if (fOffset == 0)
            throw new RuntimeException("Internal Error.");
      private class ReadThread extends Thread {
        int failed = 0;
        public void run() {
          for (int i = 0; i < 100000; i++) {
            try {
              new Inner().m1();
            } catch (Throwable t) {
              failed++;
              System.err.println("Problem on call number " + (i + 1) + " (" + t + ")");
      public void test() throws Exception {
        int numOfThreads = 100;
        ReadThread threads[] = new ReadThread[numOfThreads];
        for (int i = 0; i < numOfThreads; i++) {
          threads[i] = new ReadThread();
          threads.start();
    for (int i = 0; i < numOfThreads; i++) {
    threads[i].join();
    for (int i = 0; i < numOfThreads; i++) {
    assertEquals(0, threads[i].failed);

    Nothing jumps out at me about the code (other than
    its general convolutedness, which I assume you're
    aware of).
    What, exactly, are you observing? I assume it's that
    fOffset is zero after calling m2(), so you're
    throwing the RTE, right?Which does look like a bug to me, however, there are parts of nested class arcania that are beyond my paltry knowledge, so I may be basing that on faulty assumptions.

  • Thread problem or jvm problem?

    Hello, I've posted message on this link and now I've finished my project. Now, I have a different problem: that's why I'm posting this message here.
    if you want me to post my project code, I can , but I think it's not necessary for now... So, there are 5 classes; Main, Thread1 extends Thread, thread2 extends Thread, Thread3 extends Thread and ThreadFactory... in main method; factory instance is called for the creation of threads; so in main three type of thread instance created by factory. And right after that threads starts running and thread1 finished first, thread2 finished second, and thred3 finished third; However, the program itself never ends. There is a problem with thread endings. I've also make dubugging. Main thread creates the three of them and first main thread finishes second thread1 and the other three never finishes... keeps running.
    when main thread end it's state becomes zombie and thread1 also becomes zombie tooo.... but the other 2 of them never ends. I've tried may� things to do that: I've used finalyze() method too. Nothing chanced.
    I guessed that this may happen becouse of JVM... so what do you suggest for ending threads in a sequence like thread1, thread2, thread3, main?

    no help?

  • Monitor J2EE stack like dpmon or msmon on ABAP side

    I am attempting to monitor the J2EE stack and want to know if there is a way to get a return code back.
    Is there a command much like jcmon that would give me back a status of 1 or 0 to see if it is up. I can go to jcmon and then select a number to get the running status however I cannot interpret that with a single unix command. I know if I see dispatcher server and SDM all running that in all likelyhood the engine is up.
    If jcmon is the only tool, how can I in a script get the status of my server0 dispatcher and SDM...it seems cockeyed and messy to do this..
    I know to go to DN:50x00 to check and see manually but I nned an SAP command to give me aq return code for engine status.
    Does anyone have any idea what I could use. It seems like the ABAP stack has a number of monitors to help with this task but I can't find any on the java side.
    Thanks much,
    Mikie

    Hello Mikie,
    If I understand you correctly you are looking for a way to check if the J2EE Engine is running using a script. The easiest way is to use the ps –ef | grep jla command. It will return all jlaunch processes, one for every node (server<n>, dispatcher and SDM).  The command returns something like that:
    sr2adm    7131  6976  0 15:17 ?        00:00:28 /usr/sap/SR2/JC00/exe/jlaunch pf=/usr/sap/SR2/SYS/profile/SR2_JC00_support6 -DSAPINFO=SR2_00_dispatcher -nodeId=0 -file=/usr/sap/SR2/JC00/j2ee/cluster/instance.properties -syncSem=5013577 -nodeName=ID7416300 -jvmOutFile=/usr/sap/SR2/JC00/work/jvm_dispatcher.out -stdOutFile=/usr/sap/SR2/JC00/work/std_dispatcher.out -locOutFile=/usr/sap/SR2/JC00/work/dev_dispatcher -mode=JCONTROL pf=/usr/sap/SR2/SYS/profile/SR2_JC00_support6
    As you could see there is a lot of information and you could be more specific when grep and distinguish the jlaunch processes.
    One exception when this will not work is if the J2EE Engine is hanging. If you wish to avoid that you could use script that sends telnet request to the http port and checks the result. Something like:
    telnet localhost 50000
    GET / HTTP/1.0
    If everything works fine this should return:
    HTTP/1.1 302 Found
    If the J2EE Engine is hanging the port will not accept your request.
    Regards, Ventsi

  • Synchronizing threads of different JVM

    I have two threads running in two different JVMs. Now I want to synchronize these two threads calling a method.
    Can any one give me a solution for the same.

    I have two threads running in two different JVMs. Now
    I want to synchronize these two threads calling a
    method.
    Can any one give me a solution for the same.Presumably you think that the Java API has such a method. If so then the answer is no.
    You could write a bunch of code that uses sockets to send messages back and forth and then have one thread wait for a response. That isn't sychronization however. And conceptually it isn't a good idea to think of it that way either. Threads exist solely within a single process.

Maybe you are looking for

  • Iphone camera blurry after ios 7

    I have tried everything, nothing works. Even the new update on ios7 didn't correct it!

  • The disc you inserted was not readable by this computer.

    Every time I start up my iMac, I get the above message, with an option to Ignore or Eject. This only appeared after the latest upgrade. I have checked and there is no disc in the drive. Any ideas?

  • [SOLVED] Libreoffice icons in Arch

    Hello, I am using Arch 64bits (KDE4) and I just upgraded to Libreoffice 3.3.1. I'v read in release note that icons have changed for this version but in the KDE Kickoff menu icons look like the old OOO ones. any idea why and how to change that ? regar

  • Data nt capturing in are1 and are3 document

    dear sir, in are1 and are3 documents base exicise value is nt being captured and higher edusess 1% too but BED and educess is captured ?can anybody help me ?is ita notes problem?

  • Displaying Row Number in DataGrid

    Hi, Is there an easy way to display a Row Number (in the very first column) in DataGrid or AdvancedDataGrid ? I am trying to emulate Excel kind of functionality in DataGrid, so need to Open/Load & Save to file. I do understand that it is not difficul