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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:25:40+00:00 2026-06-12T10:25:40+00:00

I run a java code that produces a lot of read and write from/to

  • 0

I run a java code that produces a lot of read and write from/to a text file. The program source is very simple and in a loop I write 2000 lines in a test file and then I read them again just to generate a lot of read and write to the disk. But when program is running I monitor the disk by “iostat -d -x 1” I found that there is no change in read in second “r/s” but “w/s” increased as I expected!!!
This is a sample output of iostat command:

Device: rrqm/s wrqm/s  r/s   w/s    rsec/s wsec/s   avgrq-sz avgqu-sz await svctm  %util
sda     0.00   913.00  0.00  82.00  0.00   7872.00   96.00    0.58    7.09   7.11  58.30

Device: rrqm/s wrqm/s  r/s   w/s   rsec/s  wsec/s  avgrq-sz  avgqu-sz  await  svctm  %util
sda     0.00   869.00  0.00  79.00  0.00   7584.00    96.00   0.57    7.11   7.18  56.70

Device: rrqm/s wrqm/s  r/s   w/s   rsec/s  wsec/s  avgrq-sz avgqu-sz   await  svctm  %util
sda     0.00   847.00  0.00  77.00  0.00   7392.00   96.00   0.57      7.42   7.43  57.20

Device: rrqm/s wrqm/s  r/s   w/s   rsec/s  wsec/s   avgrq-sz avgqu-sz  await  svctm  %util
sda     0.00  1221.00  0.00  113.00  0.00  10760.00  95.22    0.84     7.47   7.32  82.70

As it is shown, all “r/s” are zero! but in Java program I read as much as I write in the file?! When I run the Java code, number of write per second increases, but there is no change in ” r/s” !!
Here is java code that I run when monitoring disk :

import java.io.*;

public class Test {

    public static void main(String [] args) throws IOException{

    String fileName = "/scratch/dump_file.txt";
    File f = new File(fileName);
    // Attempt to delete it
    boolean success = f.delete();
    int j=0;
    while(j<20000)
    {
        ++j;
        Writer output = null;
        String text = "A test content";
        File file = new File(fileName);
        output = new BufferedWriter(new FileWriter(file));

        int i=1;
        while(i<2000)
        {
            //Here we start writing 2000 lines into file line by line
            output.write("j==="+Integer.toString(j)+text+Integer.toString(i)+"\n");
            ++i;
        }
        output.close();
        System.out.println("Your file has been written");  

        String line = null;
        try {
            // FileReader reads text files in the default encoding.
            FileReader fileReader = new FileReader(fileName);
            BufferedReader bufferedReader = 
            new BufferedReader(fileReader);
            i=1;
            while((line = bufferedReader.readLine()) != null) {
                //Here we start reading from file line by line and show the result on screen
                ++i;
                System.out.println(line);
            }   
            // Always close file
            bufferedReader.close();         
        }
        catch(FileNotFoundException ex) {
            System.out.println(
                "Unable to open file '" + 
                fileName + "'");                
        }
        catch(IOException ex) {
            System.out.println(
                "Error reading file '" 
                + fileName + "'");                  
            // Or we could just do this: 
            // ex.printStackTrace();
        }
    }
}
}
  • 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-12T10:25:41+00:00Added an answer on June 12, 2026 at 10:25 am

    Most likely, the operating system is caching the file in RAM. Since it’s already cached in memory, when you read in Java the OS doesn’t need to actually read from the disk – it just gives you the cached copy it has already. This is a lot faster than actually reading from disk; note, however, that as iostat only reports actual disk reads and writes, your cached reads won’t show up there.

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

Sidebar

Related Questions

I'm trying to run a jar file from Java code, through exec(). The jar
I have a very simple java applet that I took from here: http://docs.oracle.com/javase/tutorial/deployment/applet/subclass.html import
I want to package a piece of code that absolutely must run on Java
I need to run an external application from within my Java code. I can
I have to write a program that is required to run several other programs
My understanding is that C/C++ produces native code to run on a particular machine
I run a Java code with the following command: $ java -Xms4G -Xmx4G myjavacode
In another discussion , someone say something about run the java code on its
This Java code compiles fine, but when I try to run it I get:
In my Java code, I occasionally run into situations where I have to catch

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.