Multiple writes to a text file

I’m thinking of implementing a mechanism, where some user-triggered agents will append to the same text file on the server. My concern is about what will happen in case more than one instance tries to append data into the file simultaneously. Will the server handle it, or do you think I will have problems with the file becoming corrupted or being locked by one instance causing other writes to fail?The data that I’m going to write is inimal, maybe less than 100 chars per write.

To test it I currently have 8 copies of a database containing 90 agents (720 total) that run every 5 minutes, writing a line to the same file. So far I didn’t see any error messages on the console and the file grows normally. It all seems ok, although there’s no way of knowing if it missed any writes…

Any ideas or suggestions about this?

thanks,

Teli

Subject: multiple writes to a text file

You should be able to trap any failures with On Error.

Subject: RE: multiple writes to a text file

I’m not sure whether LotusScript considers a file locked if it’s being accessed by a different occurrence of LotusScript. To test for sure, you need to check that the agent manager is running multiple threads, then you can try writing agents that open the file, write something, and then have long pauses (Sleep statement) before writing something else.

If the file is treated as locked, it’s not going to just have one thread wait until the other thread closes it, however; I would expect to get an error condition trying to open it.

Subject: multiple writes to a text file

Hi Teli,

An alternative you can use would be to set up an standalone database just for logging. Have the action create a new document with all the information you need, in that database. Create a scheduled agent in that new database to run on all the new documents, grab the data, write it out to the file, and delete the original document.

That way, you’d never have to worry about multiple threads creating contention- there’d only be one point of access to the file, and of course- multiple users can write multiple documents at the same time without a problem.

Also, make sure you do a good job with error trapping. If you open a file, and your script errors out before you get a chance to close the file, the file could end up remaining locked until the note server service is restarted. I’m not sure if this will happen with LotusScript agents, but I can tell you from experience that a Java Agent will hold that file in a locked state until the Domino service is restarted.

  • Steve