possible threading problem

Nate Williams nate at yogotech.com
Thu Jun 3 16:02:12 PDT 2004


[ Note, I have not analyzed the code in question, but from the sounds of
  things, the behavior the posted is probably 'acceptable' on FreeBSD. ]

> BTW: You interrupt your own thread. The javadoc's say that if the thread  
> is not blocked it will set the interrupted flag. I think that the next  
> time a blocking syscall is done the InterruptedIOException is thrown,  
> because the interrupted flag is set. So the InterruptedIOException can be  
> thrown at a very different moment than that the thread.interrupt() call  
> was done.

This is right on the money.  Different threading models will behave very
differently.  Prior to JDK1.4 on Solaris (the reference platform), you
could get *very* different results by choosing to use green threads
vs. native threads.  And, things got even more different when you
started using a JIT, which could cause behavior that appeared to be
non-deterministic.

In every good Java book, the use of 'interrupt', 'stop', and any other
method stats that the results you get *WILL* be different.  Just because
one platform behaves a particular way doesn't necessarily mean it's
correct (or that any platform is correct).

> I'm not sure about this, because I don't know enough about the
> internals of java, but it can be the reason, that it looks like a
> synchronization problem.

In the JVM, or in the code?  (I'm guessing the latter, but I want to
make sure of your intent).

> Printing more debug info, can show you
> this. But beware that the printing of the debug info can interfere
> with the rest of the program.

Back in the good 'ol days (JDK1.0/JDK1.1/JDK1.2 timeframe) when
developing a highly-threaded cross-platform product that was deployed on
Windows 95/98/NT/2000/FreeBSD/Linux/Solaris, during our testing we found
that code that we 'thought' was safe behaved extremely different from
platform to platform.  It varied from between different M$ OS products,
and even varied depending on which JVM was installed.

And, for what it's worth, this program has been tested using the FreeBSD
JDK1.4 JVM, which should be identical to the environment the poster
spoke about.

Investigation after investigation showed that in virtually every case,
the behavior we were seeing was 'acceptable' if you allowed the thread
scheduling to be completely non-deterministic (which is the case with
Java).  It may not behave like you expect, but it is certainly legal.

My .02 worth



Nate


More information about the freebsd-java mailing list