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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:24:17+00:00 2026-06-01T12:24:17+00:00

I have a program that generates a lot of data and puts it in

  • 0

I have a program that generates a lot of data and puts it in a queue to write but the problem is its generating data faster than I’m currently writing(causing it to max memory and start to slow down). Order does not matter as I plan to parse the file later.

I looked around a bit and found a few questions that helped me design my current process(but I still find it slow). Here’s my code so far:

//...background multi-threaded process keeps building the queue..
FileWriter writer = new FileWriter("foo.txt",true);
        BufferedWriter bufferWritter = new BufferedWriter(writer);
        while(!queue_of_stuff_to_write.isEmpty()) {
            String data = solutions.poll().data;
            bufferWritter.newLine();
            bufferWritter.write(data);
        }
        bufferWritter.close();

I’m pretty new to programming so I maybe assessing this wrong(maybe a hardware issue as I’m using EC2), but is there a to very quickly dump the queue results into a file or if my approach is okay can I improve it somehow? As order does not matter, does it make more sense to write to multiple files on multiple drives? Will threading make it faster?,etc..I’m not exactly sure the best approach and any suggestions would be great. My goal is to save the results of the queue(sorry no outputting to /dev/null πŸ™‚ and keep memory consumption as low as possible for my app(I’m not 100% sure but the queue fills up 15gig, so I’m assuming it’ll be a 15gig+ file).

Fastest way to write huge data in text file Java (realized I should use buffered writer)
Concurrent file write in Java on Windows (made me see that maybe multi-threading writes wasn’t a great idea)

  • 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-01T12:24:19+00:00Added an answer on June 1, 2026 at 12:24 pm

    Looking at that code, one thing that springs to mind is character encoding. You’re writing strings, but ultimately, it’s bytes that go to the streams. A writer character-to-byte encoding under the hood, and it’s doing it in the same thread that is handling writing. That may mean that there is time being spent encoding that is delaying writes, which could reduce the rate at which data is written.

    A simple change would be to use a queue of byte[] instead of String, do the encoding in the threads which push onto the queue, and have the IO code use a BufferedOutputStream rather than a BufferedWriter.

    This may also reduce memory consumption, if the encoded text takes up less than two bytes per character on average. For latin text and UTF-8 encoding, this will usually be true.

    However, i suspect it’s likely that you’re simply generating data faster than your IO subsystem can handle it. You will need to make your IO subsystem faster – either by using a faster one (if you’re on EC2, perhaps renting a faster instance, or writing to a different backend – SQS vs EBS vs local disk, etc), or by ganging several IO subsystems together in parallel somehow.

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

Sidebar

Related Questions

I have some program that generates a lot of data, to be specific encrypting
I have a working program in C++ that generates data for a Mandelbrot Set.
I have a program that generates a .shp file, and exports this as a
I have a program that generates/'rolls' two dice. I would like to output these
I have a Java program that generates Java classes for my application. Basically it
I have a Matlab program that generates a list x = 6.1692 8.1863 5.8092
I have a swing Java application that preserves a lot of data (you can
I have a program that generates the following output: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚10 day weather forecastβ”‚
I am writing a multi-threaded Java program that generates lot of random numbers. Additional
I have a program that generates some standard SQL like SELECT * FROM TEST

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.