>>>>> Mario Camou writes:
Mario> Juergen Kreileder wrote:
>> >>>>> Mario Camou writes:
>>
Mario> Hi,
Mario> I'm having some problems with threads, so I need to do a
Mario> thread dump (same thing that Ctrl-\ does) but from within
Mario> the program (i.e., I catch an Exception and want to do a
Mario> thread dump that moment). Does anyone here know how to do
Mario> that?
>>
>> You can get a partial stack trace with Thread.dumpStack, or Throwable's
>> printStackTrace method.
Mario> Oh, I know about those. I'm not interested in the stack
Mario> trace, I need the *Thread* dump. To see what I mean, hit
Mario> <Ctrl>-\ (that's ctrl+backslash) in the TTY from which
Mario> you're running a Java application.
Yep, I know what you mean but AFAIK this is the only threads information
you can get with API calls.
Mario> That's basically what I'm doing. The strange thing...I
Mario> tried to change "synchronized (data)" to "synchronized
Mario> (this)" and it magically started working.
Mario> public class Foo {
Mario> private Vector data;
Mario> public Vector getData() {
Mario> if (data == null) {
Mario> return null;
Mario> }
Mario> synchronized (data) {
Mario> while (status != LOADED) {
Mario> try {
Mario> wait();
Yes, that is 'this.wait()' and you're not the owner of this' monitor.
(You're only the owner of data's monitor). To get this' monitor you'll
have to use synchronized (this) or a synchronized method.
Mario> } catch (InterruptedException ex) {}
Mario> }
Mario> status = IDLE;
Mario> return data;
Mario> }
Mario> public void loadData() {
Mario> data = new Vector();
Mario> synchronized (data) {
Mario> try {
Mario> while (something) {
Mario> SomeObject obj;
Mario> // blah blah blah (create object obj and load data into it)
Mario> data.addElement (obj);
Mario> } finally {
Mario> notifyAll();
ditto
Mario> }
Mario> }
Mario> }
Mario> }
Mario> } // If braces don't match up, I probably added too many or too few in this
Mario> code snippet!
Juergen