0

I have a scenario where I have created Lock objects with initialization of FileOutputStream using below code. This objects are supposed to be there in application throughout lifetime.I have a static Arraylist where i will be adding this lock objects. There will be total 10 lock objects available to this application.

  Class Lock

    // instance variable
    FileOutputStream fos = new FileOutputStream(file);

    // acquire lock api()
     try
     {
         FileLock lock = fos.getChannel().tryLock();
     }
     catch(OverlappingFileLockException ex)
     {
        // Happens when lock is aquired by other resures. 
        return false;
     }


     // release lock api
     if(lock !=null)
                  lock.release

Since this objects will be there throughout lifetime of App, I am not willing to open and close the stream every time lock is requested. So, I choose to open it once while initialization. I want to know what can be the impact of this design. Also, in what way can i monitor how this leak can impact my application and system? what i suspect is whenever we restart the server the FileDescriptors will still be open. But, I am not sure what additional overhead it will cause.

Note- Servers gets restart every weekend

Your inputs will really help me to rethink and come with something else. Thanks in Advance !!

csk
  • 566
  • 1
  • 5
  • 15
  • It isn't a leak. It is a deliberate design choice on your part. – user207421 Nov 11 '16 at 09:48
  • agree ! but i am looking for the consequences for this design so that depending on severity i can reject or select this design. – csk Nov 11 '16 at 09:54
  • I don't see what choice you have. If you need the locks to persist for the life of the process you have to keep the files concerned open. But I'm wondering whether you shouldn't be using semaphores instead. File locks only work against other processes using the same file locks. They don't work against threads in the same application. – user207421 Nov 11 '16 at 11:38
  • This file system is mounted on multiple servers. Different JVMs will be using this Filesystem as Global Level Lock – csk Nov 11 '16 at 14:23
  • Network file locks don't work in many implementations. You may have problems with this design. – user207421 Nov 11 '16 at 17:28

0 Answers0