Linux threads waiting forever

From: Francis Pallini (francis.pallini_at_ecilia.fr)
Date: 02/29/04


Date: 28 Feb 2004 16:26:48 -0800

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-8)
[... 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