×

Loading...

300 intsances of 50 servlets write to the same file ....

Let me distiquish two cases

1) If you have a servlet and a few of its instances, you can create a FileWriter as instance variable. Then, synchronzed on this FileWriter as you write sth into the file.
In such a way, those servlet instances write
to the file in turn.

2) If different servlts write to the same file,
you had better create a servlet for this business. This servlet contains a FileWriter. Design this servlet use the Singleton pattern. NEXT, NEXT, NEXT, you need to bind your servlet with ServletContext. Finally, use this servlet in other servlets whenever you need to write to the file. This is the solution I can figure out. Maybe there are better solutions.
Report