>>>>> 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> Basically, I'm getting an "IllegalMonitorStateException:
Mario> current thread not owner" when I do a notifyAll(). This is
Mario> with JDK 1.1.7v1a and the green threads package.
You need a lock on the object on which you want to call notifyAll().
E.g.:
synchronized (o) {
try {
o.notifyAll();
} catch (IllegalMonitorStateException e) {
e.printStackTrace();
}
}
Note that the lock is on the object and not on the variable, that means
this code will throw an exception:
synchronized (o) {
o = referenceToAnotherObject;
try {
o.notifyAll(); // oops, we are not the owner of o's monitor
} catch (IllegalMonitorStateException e) {
e.printStackTrace();
}
}
Juergen
--
Juergen Kreileder, Universitaet Dortmund, Lehrstuhl Informatik V
Baroper Strasse 301, D-44221 Dortmund, Germany
Phone: ++49 231/755-5806, Fax: ++49 231/755-5802