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
This post has been archived. It cannot be replied.
Page address has been copied. To share, click to copy page address.
Share Online by QR Code

Back To Topic: Re #15734: how to lock a file in Java? I mean how java provide flock()?

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论