Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Linux threads waiting forever

Reply
Thread Tools

Linux threads waiting forever

 
 
Francis Pallini
Guest
Posts: n/a
 
      02-29-2004
Hello,

I am getting angry because it seems that thread synchronization
implementation of Sun under Linux is not reliable and I would like
your opinion. Maybe I am doing something wrong, something huge I don't
see.

I am using Sun JVM 1.4.2_03 (RedHat 9 up-to-date, server JVM mode,
1024 MB heap but at most 256 MB used) and I get threads waiting
forever. The following snippets come from a Java server application:

public void run() {
synchronized (this) {
try {
while (true) {
[...]
// Wait until the pool wakes up the thread or interrupts it
log.debug("Sleep...");
wait();
log.debug("Woken up!");
[...]
}
} catch (InterruptedException ie) {
// Stop thread
log.debug("Interrupted");
return;
}
}
}

public synchronized void run(Runnable target) {
log.debug("Wake up thread (" + getName() + ")");

if (target == null) {
throw new IllegalArgumentException("Null target");
}

this.target = target;
notifyAll();
}

This snippets show the only two "this" object monitor management
functions (nothing usefull hidden). Then excerpts from the log:

2004-02-27 09:59:58,738 DEBUG [Thread-8] PoolableThread:45 - Sleep...
[... nothing more about Thread-8 for two hours, then ...]
2004-02-27 11:59:34,239 DEBUG [Thread-0] PoolableThread:74 - Wake up
thread (Thread-
[... and then nothing else happens ...]

At this point, "Thread-8" even stops responding to interrupt calls. It
is lost in cyberspace (or elsewhere).

Any ideas will be very welcome. Is it possible that "wait" throws
undocumented exceptions? Please note that such problems don't araise
under Windows.

Best regards,

Francis PALLINI
 
Reply With Quote
 
 
 
 
Steve Horsley
Guest
Posts: n/a
 
      02-29-2004
Francis Pallini wrote:
> Hello,
>
> I am getting angry because it seems that thread synchronization
> implementation of Sun under Linux is not reliable and I would like
> your opinion. Maybe I am doing something wrong, something huge I don't
> see.
>
> I am using Sun JVM 1.4.2_03 (RedHat 9 up-to-date, server JVM mode,
> 1024 MB heap but at most 256 MB used) and I get threads waiting
> forever. The following snippets come from a Java server application:
>
> public void run() {
> synchronized (this) {
> try {
> while (true) {
> [...]
> // Wait until the pool wakes up the thread or interrupts it
> log.debug("Sleep...");
> wait();
> log.debug("Woken up!");
> [...]
> }
> } catch (InterruptedException ie) {
> // Stop thread
> log.debug("Interrupted");
> return;
> }
> }
> }
>
> public synchronized void run(Runnable target) {
> log.debug("Wake up thread (" + getName() + ")");
>
> if (target == null) {
> throw new IllegalArgumentException("Null target");
> }
>
> this.target = target;
> notifyAll();
> }
>
> This snippets show the only two "this" object monitor management
> functions (nothing usefull hidden). Then excerpts from the log:
>
> 2004-02-27 09:59:58,738 DEBUG [Thread-8] PoolableThread:45 - Sleep...
> [... nothing more about Thread-8 for two hours, then ...]
> 2004-02-27 11:59:34,239 DEBUG [Thread-0] PoolableThread:74 - Wake up
> thread (Thread-
> [... and then nothing else happens ...]
>
> At this point, "Thread-8" even stops responding to interrupt calls. It
> is lost in cyberspace (or elsewhere).
>
> Any ideas will be very welcome. Is it possible that "wait" throws
> undocumented exceptions? Please note that such problems don't araise
> under Windows.
>
> Best regards,
>
> Francis PALLINI


Are these two methods from the same class? If not then you have a problem.

run() waits until someone notifies THIS object.
run(Runnable) notifies THIS object.

You may be making the mistake of notifying the wrong object.

So assuming that both methods belong to the same object, one thread
will get stuck in run(), and a different thread must call
run(Runnable) to wake it. This is OK except that if the run() method
is busy (not waiting) any other thread trying to give it a Runnable
will block until the current job is finished. Which may not be
the way you intended the design to work.

Steve
 
Reply With Quote
 
 
 
 
Francis PALLINI
Guest
Posts: n/a
 
      03-04-2004
Hello Steve,

You're right to stress that point. Actually, another objet (ThreadPool) is
doing the mediation between PoolableThread (I shown a part of its code) and
its potential users. Before going to sleep, "Thread-8" (in my example) adds
itself to a synchronized list of available threads. Then, it sleeps
(actually, it "waits" and releases the monitor of "this") and the monitor of
"this" becomes available to other threads (run(Runnable) is synchronized on
that monitor).

Nevertheless, we changed our JVM from Sun to IBM. It seems now that it works
fine (a little bit too early to be sure). The only problem we encounter at
this time with IBM's JVM is their implementation of JSSE (broken with SSLv3
and OpenSSL as client peer). We had to replace it with Sun's one (we still
have to check the license about this point) and it worked fine. Also, memory
consumption is much higher, but too early to point leaks or garbage
collection differences.

Best regards,

Francis PALLINI

"Steve Horsley" <> a écrit dans le message de
news:c1spp6$17a$...

> Are these two methods from the same class? If not then you have a problem.
>
> run() waits until someone notifies THIS object.
> run(Runnable) notifies THIS object.
>
> You may be making the mistake of notifying the wrong object.
>
> So assuming that both methods belong to the same object, one thread
> will get stuck in run(), and a different thread must call
> run(Runnable) to wake it. This is OK except that if the run() method
> is busy (not waiting) any other thread trying to give it a Runnable
> will block until the current job is finished. Which may not be
> the way you intended the design to work.
>
> Steve



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
waiting threads until it gets value focode Java 2 12-27-2009 06:19 PM
Waiting all threads in a fixed thread pool yancheng.cheok@gmail.com Java 4 06-16-2007 01:52 AM
waiting Threads and processor assignment martin Java 0 08-07-2006 01:00 PM
Waiting for the end of multiple threads Andrea B. Java 4 08-31-2004 04:01 PM
Why notifyAll couldn't wake up waiting threads ? lonelyplanet999 Java 1 11-18-2003 07:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57