Limit Java console heap area?

I have a Java applet (actual <APPLET>) that generates frequent log messages in System.out. If the Java Console is enabled in the user's browser, it will of course keep the links to all those lines and prevent them from being garbage collected. The problem lies in the number of log messages kept by the console: the applet heap grows very quickly. After four days of work, it will throw an OutOfMemory exception. As far as I can tell from jmap and jhat, the log lines represent most of its fingerprint.

Is there an API for a tighter limit on the number or total size of messages stored in the Java Console? In case of an error, I only need the last few messages. The console does start deleting the oldest messages at some point, but only after it gets really huge.

I understand that "don't start the console" or "just clear the console" are possible solutions, but have you ever asked to ask a non-technical user if they have a Java console? Or try to get them through browsing and cleaning? I really would like them to leave the console on, so I see messages if there is an error.

0


source to share


1 answer


System.out.println

Use java.util.logging instead . It is much easier to change the log levels later and reduce the number of log messages.



Also check the MemoryHandler , it uses a buffer and automatically discards old log messages.

+1


source







All Articles