Rich Rich, I had zilch to do with writing this code, but as a general rule it doesn't pay to rely on the Java VM's memory management too heavily.
Imagine what would happen if the JVM was running with the default options, which include a very low maximum size for the memory allocation pool (varies by OS, but around 64MB) and a large mail was received. If you tried to store it as a ByteArray and it would just fit, all threads would experience severe performance degradation (on most JVMs they would be suspended) while garbage collection kicked in to try and clear enough memory for the new allocation. If it turns out that the ByteArray was greater than the maximum size of the available memory pool after garbage collection (i.e.: 64MB - current the working set), you would get an out of memory error. There may be more sophisticated algorithms to handle this than always writing to a file, but this solution is SAFE. IF it is a performance bottleneck, putting a byte size limited cache in front would help, but fundamentally, writing to a file is the right thing to do. -- Steve > -----Original Message----- > From: Richard O. Hammer [mailto:[EMAIL PROTECTED] > Sent: 10 June 2003 20:19 > To: [EMAIL PROTECTED] > Subject: why write an incoming message into a file? > > > I am looking at james.core.MimeMessageInputStreamSource and have a > question, perhaps for Serge since he is the author, but for anybody > else who might know. This class copies an incoming message into a > temporary file. I would like to know the motivation for this. > > In my present level of blissful ignorance, I would have guessed that > Java might keep a message for us in a byte array, even a huge byte > array, that the JVM and OS would work out where to store it, on disk > if necessary, and we happy application developers would only need to > keep a pointer to the byte array. > > But, since James has this class, there must be something I do not > understand. I understand why it makes sense to write a message to a > file when it is being stored in a mailbox. But can you explain what > makes it useful to store a message in a file at this stage of the > processing? > > Thank you, > Rich > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
