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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:07:44+00:00 2026-06-15T09:07:44+00:00

I have written a java code which is a wrapper for combining 3 different

  • 0

I have written a java code which is a wrapper for combining 3 different softwares. I run the code for 100,000 times normally. At each run, different files should be opened, re-written and closed where all happen in a correct convention of try and catch. If I run the code on a Linux server, there would be no problem. However, when I run it on my mac after 10s of 1000, the Error of Too many open files occur and subsequently error in loading file X and Y and so on and the program terminates.

one more thing I would like to add: the code runs for 1000 times, then the setting gets changed and again for 1000 times and this process repeats. so for the first 4-5 times, there would be no problem, while after 6-7 times (means 6000 runs) this error occurs.

  • 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-15T09:07:45+00:00Added an answer on June 15, 2026 at 9:07 am

    The most likely explanation is that you have a bug in your Java application that is causing it to leak file open files. The way to avoid the problem is to write your code so that file handles are always closed; e.g.

        // Using the 'try with resource' construct
        try (Reader r = new FileReader(...)) {
            // use the reader
        } catch (IOException ex) {
            // ...
        }
    

    or

        // Using classic try/catch/finally
        Reader r = null;
        try {
            r = new FileReader(...);
            // use the reader
        } catch (IOException ex) {
            // ...
        } finally {
            if (r != null) {
                try {
                    r.close();
                } catch (IOException ex) {
                    // ignore
                }
            }
        }
    

    The chances are that the program worked on one operating system and not another because the limit on the number of open files is different on the two systems. If the Java GC runs, it will close any unreachable file handles that it finds via the respective handle’s finalizer. However, this may not happen in time to prevent the “too many files open” exception.


    If your application actually requires a large number of files to be open simultaneously, you will need to lift the limit. This is best done using the ulimit shell built-in, assuming that you are using an UNIX-based operating system.

    Note however that there will still be a hard limit that it is not possible to exceed. And I believe that applies for Windows as well.

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

Sidebar

Related Questions

I have written a multi threaded java code, which when runs creates 8 threads
Let's assume I have a framework written in Java and some C++ code which
I have written a java applet which opens a JFrame (so when run in
I have written some code which passes values between java and c using jni.
I have written java code for send mail which is giving exception : when
I have written a Java code which imports an external jar file. How can
I have written a piece of Java code which is intended as to call
I often have to debug Java code which was written so that there is
I have written a piece of Java code which I am suppose to expose
I have written the java code below, which executes another java program named Newsworthy_RB.

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.