You have to hold the lock in order to do proper waits. You should use HashMap and not Hashtable in this case (you already synchronized access on Hashtable).
After a second look I could see a possible problem. Are you catching Runtime exceptions too? Also this wouldn't be an API bug but Tomcat bug. Do a search in bugzilla for it. I think that when a client drops out before receiving any response then your servlet should get an IOException on trying to write to the closed stream. Are you getting this exception on trying to write to the closed client? d. Lyubomir Pashov wrote:
Hello :-) Does anybody knows if the described below problem is a Servlet's API bug, or maybe I make a mistake? And... how to solve it? I work on Windows 2000, the Java version is J2SE 1.4.0, and I use CodeGuide 4.0 for running my servlet's application. Into the servlet's init() method I create an instance of a class which plays a role as an engine for processing the client's requests, and into the doPost(...) method I invoke relative (to the clients requests) methods from the engine's instance. One of the engine's fields is a Hashtable object, which the clients populate with concrete requests. In one of the engine's methods it is needed to to wait (using the wait( some_time ) ) for someone to fill into the Hashtable's object. And, here is the problem: If a client, which request is into the described above engine's method, is been dropped down (unexpectedly), then after elapsing the waited time, the next exception occurs (and it cannot be caught in try/catch block): ------------------------------------------------------ java.lang.IllegalStateException: Current state = FLUSHED, new state = CODING_END at java.nio.charset.CharsetEncoder.throwIllegalStateException(CharsetEncoder.java:933) at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:529) at sun.nio.cs.StreamEncoder$CharsetSE.flushLeftoverChar(StreamEncoder.java:356) at sun.nio.cs.StreamEncoder$CharsetSE.implClose(StreamEncoder.java:413) at sun.nio.cs.StreamEncoder.close(StreamEncoder.java:158) at java.io.OutputStreamWriter.close(OutputStreamWriter.java:222) at java.io.PrintWriter.close(PrintWriter.java:137) at org.apache.catalina.connector.ResponseBase.finishResponse(ResponseBase.java:482) at org.apache.catalina.connector.HttpResponseBase.finishResponse(HttpResponseBase.java:236) at org.apache.catalina.connector.http.HttpResponseImpl.finishResponse(HttpResponseImpl.java:288) at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1039) at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107) at java.lang.Thread.run(Thread.java:536) ----------------------------------------------------------- And if needed, here is the engine's method: ---------------------------- public String getRequests(long parentPID, String forUser, String userId, HttpServletRequest httpReq) { String result; try { ........ result = BChatConstants.GET_REQUESTS_REPLY + "\n"; Hashtable requests = null; // in the next line, requestedData is a Hashtable object too synchronized (requests = (Hashtable) requestedData.get(forUser)) { if (requests.isEmpty()){ requests.wait(30000); } if (requests.isEmpty()) { ......... } else { ......... ......... } } return result; }catch (Exception e) { e.printStackTrace(); } return result; } ---------------------------- Thanks, Lyubomir. ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
-- David Mossakowski Instinet Corporation **************************************************************************** <<Disclaimer>> This message is intended only for the use of the Addressee and may contain information that is PRIVILEGED and/or CONFIDENTIAL or both. This email is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this email is not an intended recipient, you have received this email in error and any review, dissemination, distribution or copying is strictly prohibited. If you have received this email in error, please notify the sender immediately by return mail and permanently deleting the copy you received. Thank you. **************************************************************************** ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html