File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes java.io.Writer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.io.Writer" Watch "java.io.Writer" New topic
Author

java.io.Writer

Michael Imhof
Greenhorn

Joined: Nov 07, 2004
Posts: 24
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?

Greez
Michael
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
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
Michael Imhof
Greenhorn

Joined: Nov 07, 2004
Posts: 24
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.

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.io.Writer