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

jabber (jabber)
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.

2000-12-1 -04:00

回到话题: Re #15734: how to lock a file in Java? I mean how java provide flock()?

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论