[DR]: I looked in the method dumpStack(), but it seems to be static, so how can I make every thread current to call it? Maybe I didn't understand the API right. No, you got it right - I forgot that the method was static. (Now I remember why I've never actually
used that method.) I guess this isn't going to work.
Another question how to support JDK 1.5 and less in the same codebase? Anything better than just use reflection to discover JDK 1.5 availability? Well, one possibility is instead of reflection, use System.getProperty("java.version") to determine what version of
Java you're using. What you do with that information is not obvious, though. It might be best to just ship two different versions of the product. I don't really know - might be best to ask this as a separate question in another forum, like Java in General Intermediate or Advanced.
As for other ways to get the thread stack dumps without JDK 5.0: well, you might be able to do something with
JPDA. I'm not sure this will work, and in particular if your code is being deployed an a variety of different app servers, it's probably going to be hard to find a way to connect the JVM to a debugger. Plus it wouldn't surprise me if it slowed down performance substantially. Dunno about that; I'm just guessing.
Also
here some other ways you may be able to get stack dumps. These are rather platform-dependent; probably no good for what you're trying to do.
I suspect that you'll just have to tell 1.4.2 users that they don't get this functionality, but if they eventually upgrade, they will.