csk
csk

Reputation: 576

Can not closing a FileOutputStream cause Issue?

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 !!

Upvotes: 0

Views: 55

Answers (0)

Related Questions