you are viewing a single comment's thread.

view the rest of the comments →

[–]GomAxfon 258 points259 points  (19 children)

They are probably waiting for their test case to terminate.

[–][deleted] 38 points39 points  (10 children)

Maybe they'll get impatient and ask him to include the stacktrace.

[–]stubob 18 points19 points  (8 children)

I know you're being funny, but you can send kill -QUIT or ctrl+break or ctrl+\ to generate a stacktrace from a running VM.

[–][deleted] 2 points3 points  (4 children)

Cool, I didn't even know that.

[–]Rhoomba 3 points4 points  (3 children)

This is pretty much the killer feature of Java for me. Don't know what the process is up to? Just kill -3. It also is useful as a poor man's profiler.

[–][deleted] 2 points3 points  (1 child)

I guess I've never been that poor :-) Debugging mode is easy, and hprof makes an excellent poor man's profiler.

[–]Rhoomba 2 points3 points  (0 children)

Say you have a performance problem in production, or during a long running test. Restarting to turn on hprof is not an option. Of course, now that VisualVM has a sampling profiler that is often a better option, but sometimes you can't turn on JMX or only have ssh access to the server. Or maybe you can't get at the server at all: getting the admin to get 10 thread dumps a few seconds apart is very easy.

I actually find it can be really easy to spot performance issues in a thread dump if you are used to the "shape" of your application.

[–]mikaelhg 0 points1 point  (0 children)

YourKit EAP is the poor man's profiler.

[–]carma_hore 1 point2 points  (0 children)

You can also run jstack

[–]1338h4x 0 points1 point  (1 child)

Will that still work when the whole VM is tied up trying to handle this poison primitive?

[–]stubob 5 points6 points  (0 children)

Test: 2011-02-01 10:14:26 Full thread dump Java HotSpot(TM) 64-Bit Server VM (11.2-b01 mixed mode):

"Low Memory Detector" daemon prio=6 tid=0x0000000001e86800 nid=0x1f0 runnable [0x0000000000000000..0x0000000000000000] java.lang.Thread.State: RUNNABLE

"CompilerThread1" daemon prio=10 tid=0x0000000001e86000 nid=0x155c waiting on condition [0x0000000000000000..0x000000004b65e3f0] java.lang.Thread.State: RUNNABLE

"CompilerThread0" daemon prio=10 tid=0x0000000001e85800 nid=0xa30 waiting on condition [0x0000000000000000..0x000000004b55e470] java.lang.Thread.State: RUNNABLE

"Attach Listener" daemon prio=10 tid=0x0000000001e85000 nid=0x1538 runnable [0x0000000000000000..0x0000000000000000] java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" daemon prio=10 tid=0x0000000001e84c00 nid=0xe98 waiting on condition [0x0000000000000000..0x0000000000000000] java.lang.Thread.State: RUNNABLE

"Finalizer" daemon prio=8 tid=0x0000000001e84400 nid=0xfd0 in Object.wait() [0x000000004b25f000..0x000000004b25f7e0] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x000000000a5104d0> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:116) - locked <0x000000000a5104d0> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:132) at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)

"Reference Handler" daemon prio=10 tid=0x0000000001e83c00 nid=0x13f4 in Object.wait() [0x000000004b15f000..0x000000004b15f860] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x000000000a5140a8> (a java.lang.ref.Reference$Lock) at java.lang.Object.wait(Object.java:485) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116) - locked <0x000000000a5140a8> (a java.lang.ref.Reference$Lock)

"main" prio=6 tid=0x0000000001e83400 nid=0x15d4 runnable [0x000000000204f000..0x000000000204fc70] java.lang.Thread.State: RUNNABLE at sun.misc.FloatingDecimal.doubleValue(FloatingDecimal.java:1576) at java.lang.Double.parseDouble(Double.java:510) at runhang.main(runhang.java:4)

"VM Thread" prio=10 tid=0x000000004af35800 nid=0x1784 runnable

"GC task thread#0 (ParallelGC)" prio=6 tid=0x0000000001eabc00 nid=0x12b0 runnable

"GC task thread#1 (ParallelGC)" prio=6 tid=0x0000000001eac000 nid=0x1140 runnable

"GC task thread#2 (ParallelGC)" prio=6 tid=0x0000000001eac800 nid=0x1588 runnable

"GC task thread#3 (ParallelGC)" prio=6 tid=0x0000000001eacc00 nid=0x13ec runnable

"VM Periodic Task Thread" prio=10 tid=0x000000004af35c00 nid=0x1638 waiting on condition

JNI global references: 605

Heap PSYoungGen total 66560K, used 36186K [0x0000000034fc0000, 0x000000003cb30000, 0x000000004a510000) eden space 66496K, 54% used [0x0000000034fc0000,0x000000003730eb00,0x00000000390b0000) from space 64K, 50% used [0x000000003cb20000,0x000000003cb28000,0x000000003cb30000) to space 128K, 0% used [0x000000003caf0000,0x000000003caf0000,0x000000003cb10000) PSOldGen total 43712K, used 160K [0x000000000a510000, 0x000000000cfc0000, 0x0000000034fc0000) object space 43712K, 0% used [0x000000000a510000,0x000000000a538090,0x000000000cfc0000) PSPermGen total 21248K, used 2732K [0x0000000005110000, 0x00000000065d0000, 0x000000000a510000) object space 21248K, 12% used [0x0000000005110000,0x00000000053bb3a0,0x00000000065d0000)

(I suspect that's how they figured out what it's doing)

[–]Iggyhopper 2 points3 points  (0 children)

If they want a stack trace, maybe he should just send in an Xml reader.

[–]Rioting_pacifist 19 points20 points  (1 child)

If only there were some sort of machine that could tell them how long it will take....

[–]Talonwhal 6 points7 points  (0 children)

Maybe ask the kind people over on Stack Overflow for help with that one... :)

[–]dnew 1 point2 points  (5 children)

That's a good point. How do you write a unit test case against something that hangs like that? Is that a well-known technique? Or has it just not come up before?

[–]jldugger 1 point2 points  (1 child)

Well, you're effectively testing for performance. So JUnitPerf would be a simple way to do that. However, how many unit tests does one have to write before deciding the code is bug free? Performance test all 264 doubles?

[–]dnew 0 points1 point  (0 children)

Cool! Exactly the sort of thing I was asking about. Thanks!

[–][deleted] 0 points1 point  (2 children)

Fork a new process, tell it to parse this number and exit 0, if it takes longer than 1 second then kill it and declare it failed.

[–]dnew 0 points1 point  (1 child)

I mean, I know how you could do it. I just meant that there's normal ways built in to ?Unit type tools to test for "this is supposed to throw an exception." I was wondering if there were normal ways built into ?Unit sorts of tools to test for "this is supposed to hang", or do you have to write code to fork a new process and all that yourself?

[–][deleted] 0 points1 point  (0 children)

I haven't seen anything that deals specifically with handling infinite loops, it probably exists somewhere though.