Juergen,
Thanx for the quick response. See below
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.
Oh, I know about those. I'm not interested in the stack trace, I need the
*Thread* dump. To see what I mean, hit <Ctrl>-\ (that's ctrl+backslash) in the
TTY from which you're running a Java application.
> 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();
> }
> }
That's basically what I'm doing. The strange thing...I tried to change
"synchronized (data)" to "synchronized (this)" and it magically started working.
Any ideas?:
public class Foo {
private Vector data;
public Vector getData() {
if (data == null) {
return null;
}
synchronized (data) {
while (status != LOADED) {
try {
wait();
} catch (InterruptedException ex) {}
}
status = IDLE;
return data;
}
public void loadData() {
data = new Vector();
synchronized (data) {
try {
while (something) {
SomeObject obj;
// blah blah blah (create object obj and load data into it)
data.addElement (obj);
} finally {
notifyAll();
}
}
}
}
} // If braces don't match up, I probably added too many or too few in this
code snippet!