Our personal Writer class is a subclass of java.io.Writer and implements the abstract methode write(char, int, int). It's working fine but from time to time we got an IllegalStateException. It looks like this exception is thrown from our implemention of the abstract write method.
Can I fix this problem by synchronizing the lock variable of the java.io.Writer class?
If this solves the problem, can somebody explain to me why?
Exactly where did the exception get thrown from? That would appear to be critical in understanding the cause. Incidently, adding character by character to a String has horrible performance - what is your reason for this? Why not use the String constructor that takes char, off and len directly? Bill
Joined: Nov 07, 2004
Sorry Bill, I didn't look at the details of the code. It's some old code running for years (never change a running code!!). But you're right. Using the String constructor would be more efficient.
Back to the IllegalStateException: Our own class (who implements the abstract write method of java.io.Writer) is called SdkDatabaseLogWriter and is shown in the code above. We replaced the Writer for TOPLink Messages by our own Writer. That's why the TOPLink Session.logMessage is calling finally our writer.
Author and all-around good cowpoke
Joined: Mar 22, 2000
So you get an IllegalMonitorStateException (not IllegalStateException). As far as I know, that is only thrown when a Thread tries to wait() or notify() when it does not own a lock on an object. So that would indicate a synchronization issue of some sort - explains why it only happens occasionally. Toplink session is where I would look - probably it wants to synchronize on the log writer to ensure only one Thread at a time uses it. Bill [ December 23, 2004: Message edited by: William Brogden ]