14 Replies Latest reply: May 25, 2012 7:47 AM by gimbal2 RSS

    Java Thread waiting issue

    901290
      Hi,

      We are facing an issue in our java code wherein the threads goes in waiting state.

      Following is thread dump for the issue. Any help on the same is appreciated

      Threaddump:-

      "Thread-74" prio=5 tid=0x005541c8 nid=0x55 waiting on condition [0x6d57f000..0x6d57fc28]
      at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:983)
      at java.lang.Float.parseFloat(Float.java:222)
      ....
      ....
      "Thread-73" prio=5 tid=0x005535d0 nid=0x54 waiting on condition [0x6d67f000..0x6d67fc28]
      at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:983)
      at java.lang.Float.parseFloat(Float.java:222)
      ....
      ....
      -
      -
      -
      -
      "Thread-1" prio=5 tid=0x0035e1b8 nid=0xc waiting on condition [0x71e7f000..0x71e7fc28]
      at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:983)
      at java.lang.Float.parseFloat(Float.java:222)
      ....
      ....
                
      "Thread-0" prio=5 tid=0x003a2190 nid=0xb waiting on condition [0x71f7f000..0x71f7fc28]
      at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:983)
      at java.lang.Float.parseFloat(Float.java:222)
      ....
      ....

      "Signal Dispatcher" daemon prio=10 tid=0x000f76e8 nid=0x6 waiting on condition [0x00000000..0x00000000]

      "Finalizer" daemon prio=8 tid=0x000f2778 nid=0x4 in Object.wait() [0xfc67f000..0xfc67fc28]
      at java.lang.Object.wait(Native Method)
      - waiting on <0xa02a19a0> (a java.lang.ref.ReferenceQueue$Lock)
      at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
      - locked <0xa02a19a0> (a java.lang.ref.ReferenceQueue$Lock)
      at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
      at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)

      "Reference Handler" daemon prio=10 tid=0x000f1610 nid=0x3 in Object.wait() [0xfc77f000..0xfc77fc28]
      at java.lang.Object.wait(Native Method)
      - waiting on <0xa02a02f0> (a java.lang.ref.Reference$Lock)
      at java.lang.Object.wait(Object.java:429)
      at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:115)
      - locked <0xa02a02f0> (a java.lang.ref.Reference$Lock)

      "VM Thread" prio=5 tid=0x000f0ff0 nid=0x2 runnable

      "VM Periodic Task Thread" prio=10 tid=0x000fbe60 nid=0xa waiting on condition
      "Suspend Checker Thread" prio=10 tid=0x000f6db0 nid=0x5 runnable




      Thanks and Regards,
      Navin
        • 1. Re: Java Thread waiting issue
          796440
          898287 wrote:
          Hi,

          We are facing an issue in our java code wherein the threads goes in waiting state.
          So? That's perfectly normal. Threads do it all the time. It's part of the way they operate.

          Perhaps your point is that they go into that state and never come out?

          There's not enough detail to be sure exactly what's happening, but this is in fact what you're talking about then it's almost certain that either a) You have a deadlock in your code or b) You have a bug in your code whereby you're calling wait() without guaranteeing that the waiting thread will be awakened by notify(), notifyAll(), a timeout, or an interrupt.
          • 2. Re: Java Thread waiting issue
            901290
            Hi,

            thanks for your reply.

            Yes, i do agree that this is perfectly normal behaviour for threads. The issue is that the processing doesn't stuck anywhere, but it slows down tremendously.

            When we restart our application after this point everything works in normal way. [The rate of incoming files for processing is the almost same]

            Just trying to find how come all threads waiting at parseFloat() function? Something weird :(



            Thanks,
            Navin
            • 3. Re: Java Thread waiting issue
              EJP
              So which of these waiting threads is causing the problem?
              • 4. Re: Java Thread waiting issue
                901290
                Didn't get your question?

                Each thread is processing one file at a time. So not sure which thread is causing the issue.

                Out of 75 threads, 74 are "waiting on condition" [at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:983)
                        at java.lang.Float.parseFloat(Float.java:222) ]

                1 thread is "runnable" [at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:983)
                        at java.lang.Float.parseFloat(Float.java:222)]


                Thanks,
                Navin
                • 5. Re: Java Thread waiting issue
                  gimbal2
                  Ok, but all the information you give basically only says one thing "something is happening which I cannot explain". Well neither can anyone else as nobody has access to your machine.

                  The only thing that can be deduced from what you post is that apparently you are reading float values from a file at some point and that gets stuck. If you want any kind of assistance, it would be wise to post some code where the problem is likely happening.
                  • 6. Re: Java Thread waiting issue
                    901290
                    Understand that the details are not sufficient :(

                    Won't be able to provide details of Production code here
                    please find below some snippets...

                    fmtVal = Float.parseFloat(listValue.get(2).toString());

                    ....
                    fmtVal1 = Float.parseFloat(listValue.get(3).toString());
                    • 7. Re: Java Thread waiting issue
                      gimbal2
                      898287 wrote:
                      Won't be able to provide details of Production code here
                      You don't have to, but if you want help you'll have to create a small, compilable and runnable application that demonstrates the problem. Perhaps in creating that small demonstration program you'll already figure out what's going on, it has happened before.
                      • 8. Re: Java Thread waiting issue
                        ++sja
                        What JVM version do you have, what does "java -version" say? Try a recent version.

                        Try the optimizing compiler, i.e. "java -server".

                        Are you giving Float.parseFloat() lots of empty strings, or strings that are all white space, or strings that do not represent floats? Those cause exceptions that can slow things down. See if Float.parseFloat() is throwing exceptions.

                        I can't see how FloatingDecimal.readJavaFormatString() would wait in the version of JVM that I have in front of me; there is no obvious sychronization in it.
                        • 9. Re: Java Thread waiting issue
                          901290
                          Java Version is 1.4.2_12.

                          We are running our program something like below on linux server.

                          java -server -Xms1024M -Xmx2048M ourclass
                          • 10. Re: Java Thread waiting issue
                            gimbal2
                            898287 wrote:
                            Java Version is 1.4.2_12.
                            Not only an incredibly old version of Java, it is on top of that a very old version of Java 1.4.2. I would try at least to upgrade to the latest release of Java 1.4.2 to see if that changes anything, for all you know you're running into a bug that was already fixed.

                            http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase14-419411.html
                            • 11. Re: Java Thread waiting issue
                              901290
                              Hi All,

                              As per suggestions received we have upgraded to Java 1.5 on dev box and observed that the issue doesn't occur :).

                              Strange behavior by code is that the mentioned issue doesn't occur everytime with Java 1.4.2 also. It only occurs when we start our application after any
                              deployment. Once we restart the application (in some cases 2 or 3 times) the issue doesn't occur.

                              As mentioned by gimbal2 we are hitting a bug in Java 1.4.2. If this is the case then the code shouldn't work even if we restart our application once or twice.

                              Any ideas?


                              Regards,
                              Navin
                              • 12. Re: Java Thread waiting issue
                                gimbal2
                                Bugs that don't happen at all times are the most likely ones to actually appear in the JDK you know; they won't be apparent during testing rounds so they have the biggest chance of slipping through until developers run into them. After that its a battle to actually get it fixed as Sun/Oracle can't do anything if the problem cannot be reproduced.

                                The main problem is that you're running on seriously outdated, unsupported and potentially risky software (from a security perspective). Asking for any kind of help especially in a user to user forum is basically pointless, the only real answer is not run software that is a decade old. Or get an Oracle support contract of course, I believe they still do fixes to 1.4 if you pay for it.
                                • 13. Re: Java Thread waiting issue
                                  901290
                                  Thanks to you all for all your help. We will upgrade to latest version.

                                  Closing the thread.



                                  Regards,
                                  Navin
                                  • 14. Re: Java Thread waiting issue
                                    gimbal2
                                    898287 wrote:
                                    Thanks to you all for all your help. We will upgrade to latest version.
                                    Good for you - it doesn't happen often that people are actually mentally strong enough to dare make that decision.

                                    Now I must warn you that this may not be without cost either as you may need to patch some code due to minor differences in Java 5 and up. I hope you didn't use variables named 'enum' for example, as that has become a keyword. I'm probably passing out this advice needlessly but I do it anyway: test thoroughly first.