Subj : Re: How do I use the Java API in a Thread-Safe Manner? To : comp.programming.threads From : David Hopwood Date : Wed Jun 22 2005 01:44 am Al Koch wrote: > It is my understanding that, in general, the J2SE 1.4 API is *not* > thread-safe. [...] > The synchronize(this) guarantees that no other thread can enter *my code > block* in MyMethod() but (as far as I can tell) it in no way prevents > another thread from entering UnsafeAPI() from another block of code, either > in my servlet or even in another application altogether. APIs in Java are not functions, they are class interfaces. What the references you found mean by saying that the API is not in general thread-safe, is that if you use the *same* API object from multiple threads, there may not be any synchronization (unless the documentation says there is). If you create objects that are only accessible to code that you write, OTOH, then you can ensure the necessary synchronization when using those objects. This argument may not apply to static methods of some API classes. Another application running in a separate JVM process cannot affect the thread-safety of your application. It can access external resources like files at the same time, of course, and you'll have to use locking (see java.nio.FileChannel and FileLock) if that is important. -- David Hopwood .