Home Segments Top Top Previous Next

1050: Mainline

Ordinarily, servlet servers are content to handle multiple requests simultaneously, by wrapping each in its own thread. Accordingly, if your servlets write information to a file, you need to worry about what happens if one client's work is underway when another client's request arrives. Otherwise, you risk having one client step on another's toes, as explained in Segment 902.

The easiest way to avoid multiple-thread toe stomping is to have your servlets implement the SingleThreadModel interface, as does the servlet defined in Segment 1049, which shuts off multithreading. Otherwise, you need to use Java's synchronization mechanism to protect state-retaining files, as explained in Segment 903.