Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7492203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:23:38+00:00 2026-05-29T16:23:38+00:00

Premises: I get OverlappingFileLockException every time i try to lock a file (this applies

  • 0

Premises:

  • I get OverlappingFileLockException every time i try to lock a file (this applies to all files)
  • I have a freshly booted machine
  • Tested on both Windows/Linux through Eclipse, java v1.6
  • Just one instance of Eclipse is running with this single program
  • Just one thread running in this program (event dispatching thread)
  • I have tried to lock files that i have never touched before
  • Same problem using both lock() and trylock()
  • Changing from FileOutputStream() to RandomAccessFile() yields same result

I am trying to lock a file in a static function, the function returns a composed object that contains the channel and the lock so another function, unlockFile(FileLocking fl) can be used to close then channel and release the lock. The composed object class looks like this:
`

   public class FileLocking {
    public FileChannel channel;
    public FileLock lock;

    public FileLocking(FileChannel f, FileLock l) {
        channel = f;
        lock = l;
    }

The function that locks the file looks like this:

public static synchronized FileLocking lockFile(String fileName) {
FileLocking result = null;
FileChannel channel = null;
try {
    channel = new FileOutputStream(fileName).getChannel();
    FileLock lock = channel.lock();
    lock = channel.tryLock();
    result = new FileLocking(channel, lock);
} catch (Exception e) {
    Log(ERR, "Exception when locking " + e.getMessage());
    e.printStackTrace();
} finally {
    try {
        channel.close();
    } catch (IOException e) {
        Log(ERR, "IOE: " + e.getMessage());
        e.printStackTrace();
    }
}
return result;

}

Currently, i get the following error:

[ERR]: (pid:13) Exception when locking null
java.nio.channels.OverlappingFileLockException
at sun.nio.ch.FileChannelImpl$SharedFileLockTable.checkList(Unknown Source)
at sun.nio.ch.FileChannelImpl$SharedFileLockTable.add(Unknown Source)
at sun.nio.ch.FileChannelImpl.tryLock(Unknown Source)
at java.nio.channels.FileChannel.tryLock(Unknown Source)
at com.xxx.utils.FileLocking.lockFile(FileLocking.java:29)`

Explanations and/or coding techniques are highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T16:23:38+00:00Added an answer on May 29, 2026 at 4:23 pm

    Why do you call tryLock after lock again ? Am I missing something ?

    You get OverlappingFileLockException since the lock is already held by the JVM, when you invoke tryLock second time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All, Wanted to get a few thoughts on this. Lately I am becoming more
Premise: I've started to study javascript and the DOM and I have this HTML
Ok, so I've been trying to get my head around this, but I'm struggling.
I have a large number of 2D points and I want to quickly get
I have an application that interacts with MSCRM 4.0. When I try to update
Rails docs have this information for Object#blank? An object is blank if it’s false,
I decided to give MongoDB a try and see how well we get along.
I have added CRM 2011 (on-premises) Deployment and Discovery Services as web Reference (instead
In on-premises Microsoft SQL Server, when I issue this query: SELECT * FROM sys.dm_exec_sessions
I create method for select current premises foto, all works good public function findByDistrictIds($criteria)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.