DeadLock on sun.nio.cs.StandardCharsets
Dear all,
I found a deadlock problem, and it seems that the problem appears in calling java.nio.charset.Charset.lookup at runtime.
I use JavaMail for sending emails, and it works very well for a long time. But one day, I found that no email can be sent. Then, I ran thread dump to see what was happening, and I found that the sun.nio.cs.StandardCharsets is locked, and other processes are waiting for this resource. This never release and cause a deadlock.
Let me post the details of thread dump below:
This thread is waiting to lock
"Thread-339" daemon prio=1 tid=0x4aa22600 nid=0x3867 waiting for monitor entry [0x4ca74000..0x4ca7521c]
at sun.nio.cs.FastCharsetProvider.charsetForName(FastCharsetProvider.java:119)
- waiting to lock <0x5447c180> (a sun.nio.cs.StandardCharsets)
at java.nio.charset.Charset.lookup(Charset.java:433)
at java.nio.charset.Charset.isSupported(Charset.java:461)
at sun.nio.cs.StreamEncoder.forOutputStreamWriter(StreamEncoder.java:68)
at java.io.OutputStreamWriter.<init>(OutputStreamWriter.java:82)
at com.sun.mail.handlers.text_plain.writeTo(text_plain.java:112)
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:839)
at javax.activation.DataHandler.writeTo(DataHandler.java:295)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1206)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:707)
at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:256)
at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:67)
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:839)
at javax.activation.DataHandler.writeTo(DataHandler.java:295)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1206)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1611)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:526)
There is one thread which has the lock and has not released it:
"Thread-342" daemon prio=1 tid=0x4aaf95e8 nid=0x386e waiting on condition [0x4c773000..0x4c77459c]
at sun.util.PreHashedMap.get(PreHashedMap.java:118)
at sun.nio.cs.FastCharsetProvider.lookup(FastCharsetProvider.java:85)
at sun.nio.cs.FastCharsetProvider.charsetForName(FastCharsetProvider.java:119)
- locked <0x5447c180> (a sun.nio.cs.StandardCharsets)
at java.nio.charset.Charset.lookup(Charset.java:433)
at java.nio.charset.Charset.isSupported(Charset.java:461)
at sun.nio.cs.StreamEncoder.forOutputStreamWriter(StreamEncoder.java:68)
at java.io.OutputStreamWriter.<init>(OutputStreamWriter.java:82)
at com.sun.mail.handlers.text_plain.writeTo(text_plain.java:112)
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:839)
at javax.activation.DataHandler.writeTo(DataHandler.java:295)
at javax.mail.internet.MimeUtility.getEncoding(MimeUtility.java:230)
at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1124)
at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:863)
at javax.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:239)
at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1111)
at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:1927)
at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1908)
The sun.nio.cs.StandardCharsets comes from Java standard runtime library (../jre/rt.jar). I user JavaMail to send emails with SMTP. It seems that the problem is the underlying implementation of JavaMail. Is it a bug of JavaMail? Has anyone experienced this before? And how this deadlock be happened?
Thanks very much.
Sirius