Reentrant (was Re: [jdom-interest] Re: JDOM -- threads?)

Mattias Jiderhamn mj-lists at expertsystems.se
Thu May 11 22:15:04 PDT 2006


Thread-safe and reentrant are two different - though related - 
aspects of a class.
A thread-safe instance may be used concurrently by several different threads.
A reentrant instance may be used several times sequetially, by 
different threads OR the same thread.

Obviously, if a thread is non-reentrant, it is most probably not 
thread-safe, though it can be reentrant but not thread-safe.
So you could say that thread-safe classes is a subset of reentrant classes.


And no, synchronized does not mean that the thread is guaranteed to 
complete the synchronized block before being interrupted, is just 
means no other thread may enter the SAME synchronized block, until 
that thread is finished. Though other threads may be assigned CPU 
time and execute other methods, before the thread has finished the 
synchronized block.
(See 
http://java.sun.com/docs/books/tutorial/essential/threads/multithreaded.html)


Anyway, this list is not the place to discuss basic Java 
understanding such as threading or streams and writers. Please review 
a tutorial (such as 
http://java.sun.com/docs/books/tutorial/index.html) or a "Java for 
Dummies" book first, and then find another forum if you have 
questions not related to JDOM.


At 2006-05-11 23:04, Mike.Brenner wrote:
>Ummmh. I thought not thread-safe meant
>non-reentrant code, so that operations
>in one thread can interfere with
>operations in another thread;
>if you bring in "interrupted by another thread"
>you limit yourself to a particular
>implementation of threads.
>
>
>
>
>Anderson, Paul D wrote:
>>"Not thread-safe" means that operations running in one thread may not
>>complete properly if that thread is interrupted by another.
>>The simplest solution (but perhaps not the most efficient) is to label
>>any unsafe operations "synchronized". This means the operation will run
>>to completion before the other thread is allowed to interrupt.
>>Many functions and features are not thread-safe because guaranteeing
>>thread safety can be complicated and inefficient. IMHO you really
>>shouldn't do thread-based programming without a little education first
>>-- the Java Tutorial is a good place to get more info.
>>
>>
>>>-----Original Message-----
>>>From: Frances [mailto:fdr58 at yahoo.com] Sent: Thursday, May 11, 2006 11:33 AM
>>>To: jdom-interest at jdom.org
>>>Subject: [jdom-interest] Re: JDOM -- threads?
>>>
>>>Frances wrote:
>>>>just read in jdom.org that JDOM is not thread-safe..  what
>>>does this
>>>>mean exactly? (don't know much about threads..)  that JDOM does 
>>>>not include thread APIs, or that you can't do threads AT ALL
>>>with it?  For
>>>>my project I have to be able to set threads...
>>>>
>>>>(can I use thread-related classes from system API to make it thread-safe?)
>>>and what about DOM, SAX API?  what are best alternatives for 
>>>creating XML? (just Java I/O?  JavaScript?  any better ideas?)  thanks...



More information about the jdom-interest mailing list