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

  • SEARCH
  • Home
  • 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 8803547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:21:59+00:00 2026-06-14T01:21:59+00:00

Im investigating the possibility of re-writing some code that bottlenecks on disk writes into

  • 0

Im investigating the possibility of re-writing some code that bottlenecks on disk writes into java. The javadoc does not make clear why the first two code loops below would perform so differently to the second two loops:

public void testFileChannel() throws IOException {
    RandomAccessFile raf = new RandomAccessFile(new File("/tmp/t5"),"rw");
    FileChannel c = raf.getChannel();
    c.force(true);
    ByteBuffer b = ByteBuffer.allocateDirect(64*1024);
    long s = System.currentTimeMillis();
    for(int i=0;i<size;i++){            
        b.clear();
        b.put(data.getBytes());
        b.flip();
        c.write(b);
    }
    long e=System.currentTimeMillis();
    raf.close();
    System.out.println("FileChannel rw force=true "+(e-s));

    raf = new RandomAccessFile(new File("/tmp/t5"),"rw");
    raf.seek(0);
    c = raf.getChannel();
    c.force(false);
    b = ByteBuffer.allocateDirect(64*1024);
    s = System.currentTimeMillis();
    for(int i=0;i<size;i++){            
        b.clear();
        b.put(data.getBytes());
        b.flip();
        c.write(b);
    }
    e=System.currentTimeMillis();
    raf.close();
    System.out.println("FileChannel rw force=false "+(e-s));

    raf = new RandomAccessFile(new File("/tmp/t5"),"rwd");
    raf.seek(0);
    c = raf.getChannel();
    c.force(true);
    b = ByteBuffer.allocateDirect(64*1024);
    s = System.currentTimeMillis();
    for(int i=0;i<size;i++){            
        b.clear();
        b.put(data.getBytes());
        b.flip();
        c.write(b);
    }
    e=System.currentTimeMillis();
    raf.close();
    System.out.println("FileChannel rwd force=true "+(e-s));


    raf = new RandomAccessFile(new File("/tmp/t5"),"rwd");
    raf.seek(0);
    c = raf.getChannel();
    c.force(true);
    b = ByteBuffer.allocateDirect(64*1024);
    s = System.currentTimeMillis();
    for(int i=0;i<size;i++){            
        b.clear();
        b.put(data.getBytes());
        b.flip();
        c.write(b);
    }
    e=System.currentTimeMillis();
    raf.close();
    System.out.println("FileChannel rws force=true "+(e-s));
}

public static final int size = 10000;
public static final String data = "123456789012345678901234567890";

Running this code produces something like this:

FileChannel rw force=true 273
FileChannel rw force=false 40 // Forcing writes to disk is slower than above.
FileChannel rwd force=true 4179 // Why is this slower?!
FileChannel rwd force=true 4212

As you can see, c.force(true) slows things down a little. Why should things slow down more when using the RandomAccessFile “rwd” mode. Shouldnt “rwd” and c.force(true) be equivalent.

  • 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-14T01:22:00+00:00Added an answer on June 14, 2026 at 1:22 am

    According to JavaDoc, c.force(whatever) just push the things to the disk before that method returns, while open with “rwd” do that for every I/O.

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

Sidebar

Related Questions

Whilst investigating an internationalisation issue in some Java code whereby on a Japanese Windows
I'm actually investigating the possibility to have an application that fulfill the following requirements:
I was investigating some framework code (the System.AppDomain.GetDynamicDir method) and this was all the
I'm investigating the possibility to develop Flash or FlashLite apps that runs on Android
I'm currently investigating the possibility to force the rvct compiler not to link in
I'm investigating aurioTouch2 sample code. And I noticed, that when we analize audio data,
I'm investigating Magento's infamous price block/ price.phtml file, and I've run into something that
I am currently investigating the possibility to incorporate MVC into our existing WebForms framework.
I am investigating the possibility of using Git for code management for my Company.
I'm currently investigating the possibility to use custom attributes derived from ActionFilterAttribute. I want

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.