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 8284531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:08:32+00:00 2026-06-08T11:08:32+00:00

I have some confusions on java file lock. here’s my situation. Each thread can

  • 0

I have some confusions on java file lock.

here’s my situation.

  1. Each thread can read/write a file.
  2. My file manipulating method can be called by several threads at the same time

and, my goal is clear, no concurrent write to a file by threads. Always one thread allowed to write a file.

My questions are

  1. If FileOutputStream.write() was thread safe, I didn’t have to put any concurrency mechanism in my code since the code at the write() will block until a locked file will be released. However, my program would not seem to block when a file is opened by a thread (i am not sure for this)

  2. If FileOutputStream.write() was NOT thread safe, I would have to write additional code to make a file accessed by only thread at a time. Therefore, I used FileChannel.lock() to do so. However, different from the JDK document it does not block but throw an OverlappingFileLockException.

I would appreciate your clear advise.

  • 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-06-08T11:08:33+00:00Added an answer on June 8, 2026 at 11:08 am

    It is not thread safe and you need to programmatically ensure safety. Just put the relevant code in a synchronized block assuming there is no major performance requirement for your app.

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

Sidebar

Related Questions

I am developing a Java Desktop Application but have some confusions in choosing a
Yes, this is an old topic, but I still have some confusions. In Java,
I have some confusion in understanding Java Security model. In my ${JDK_HOME}/jre/lib/security/java.policy file, I
I am learning JPA from this tutorial . I have some confusions in understanding
I'm new to android. I have some java knowledge (not extensive), and I've done
I have inherited a bit of Java code that uses Hibernate. Some of the
I have some confusion about generic programming in java: If Manager is subclass of
I have some code that's currently giving me an error, because recur can only
I have some confusion regarding where you put regular java code in an android
Having read many tutorials, articles and questions, I am still have confusions about updating

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.