Java: is Exception class thread-safe?

Posted by Vilius Normantas on Stack Overflow See other posts from Stack Overflow or by Vilius Normantas
Published on 2010-04-19T15:27:17Z Indexed on 2010/04/19 15:33 UTC
Read the original article Hit count: 256

Filed under:
|
|

As I understand, Java's Exception class is certainly not immutable (methods like initCause and setStackTrace give some clues about that). So is it at least thread-safe? Suppose one of my classes has a field like this:

private final Exception myException;

Can I safely expose this field to multiple threads? I'm not willing to discuss concrete cases where and why this situation could occur. My question is more about the principle: can I tell that a class which exposes field of Exception type is thread-safe?

Another example:

class CustomException extends Exception
{
   ...
}

Is this class thread-safe?

© Stack Overflow or respective owner

Related posts about java

Related posts about exception