This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.io.Writer

 
Michael Imhof
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic