Where is the file descriptor leak in this code?

The following "appendStringToFile" method is used to append a String to a file. My java app calls this method a few times per minute, and then crashes after running for about 12 hours. The exception is "Too many open files". The code that calls it does so from a synchronized block, so concurrency is not the problem, and it would seem that only one file descriptor should be used at a time.
Can anyone find the problem?
     public static void createParentDirectoryIfNeeded(String path) {
          String dirPath = path.substring(0, path.lastIndexOf('/'));
          File dir = new File(dirPath);
          if (!dir.exists()) {
               dir.mkdirs();
     public static void appendStringToFile(String s, String path) {
          FileWriter fileWriter = null;
          try {
               createParentDirectoryIfNeeded(path);
               // create file if it doesn't already exist
               File file = new File(path);
               file.createNewFile();
               if (s != null) {
                    fileWriter = new FileWriter(file, true);
                    fileWriter.write(s.toCharArray());
          } catch (IOException ioe) {
               ErrorHandler.handleError(ioe, LOG);
          } finally {
               if (fileWriter != null) {
                    try {
                         fileWriter.close();
                    } catch (IOException ioe) {
                         ErrorHandler.handleError(ioe, LOG);
     }Edited by: mikewertheim on Sep 26, 2008 11:54 AM
Edited by: mikewertheim on Sep 26, 2008 11:54 AM
Edited by: mikewertheim on Sep 26, 2008 11:55 AM
Edited by: mikewertheim on Sep 26, 2008 11:56 AM

I don't know what is causing your problem but I can suggest several improvements.
1) Given a file 'f' then one can create the parent directory using   f.getParentFile().mkdirs();so that one does not need to useString dirPath = path.substring(0, path.lastIndexOf('/'));          2) There is not need to test if the directory exists before creating it. If it exists then   f.getParentFile().mkdirs(); will just do nothing.
3) There is no need to usefile.createNewFile();because if the file does not exist then fileWriter = new FileWriter(file, true);will create it.

Similar Messages

  • Where are the files for the Backups that show up in About This Mac - Storage?

    Where are the files for the Backups that show up in About This Mac - Storage?
    My new Macbook Pro 13 retina has 1TB flash drive. But despite my TimeMachine being in a TimeCapsule my Macintosh HD shows 277 Gb of space has Backups. What is this for? How can I delete it?

    OS X Lion and newer Mac OS X versions create local snapshots in portable Macs if Time Machine is enabled. See > http://pondini.org/TM/30.html
    You don't have to worry about. They are stored in a kind of volume named "MobileBackups", but they appear as stored in your hard drive. To delete them, open System Preferences > Time Machine, and turn off Time Machine. Then, turn it on. However, you don't need to delete them, as they will be deleted when your hard drive gets full

  • WHen I choose an album, upload a file(s), just as the file(s) is uploaded the file I have chosen disappears and I am asked to choose album again. If I ignore this and drag a file onto the sceneline, I get the "where is the file " message" and when click o

    WHen I choose an album, upload a file(s), just as the file(s) is uploaded the file I have chosen disappears and I am asked to choose album again. If I ignore this and drag a file onto the sceneline, I get the "where is the file " message" and when click on the file it is looking for I get the message "This type of file is not supported, or the required codec is not installed". I have made many little films before but always have this problem now. Any suggestions?

    Margaret
    Although we are continents apart - Australia (Perth) vs North America (US), we will not let time zones interfere with getting your Premiere Elements 8.0/8.0.1 working.
    1. The usual Premiere Elements 8 drill.
    a. Are the automatic features of Background Rendering and AutoAnalzyer turned Off?
    For Background Rendering, see Premiere Elements workspace Edit Menu/Preferences/General. For AutoAnalzyer, see Elements Organizer workspace Edit Menu/Preferences/AutoAnalyzer Options.
    b. Are you running the program from the 8.0.1 Update? If not, see Help Menu/Update?
    c. Do you have the latest version of QuickTime installed on your computer with Premiere Elements 8.0/8.0.1?
    Apple - QuickTime - Download
    2. The usual computer drill....for your Windows XP 32 bit (SP3, I presume)
    a. Is computer opitimized, defragmented, etc.
    CCleaner - PC Optimization and Cleaning - Free Download
    b. Are you running your computer from a User Account with Administrative Privileges? That is important for Premiere Elements 8 as well as for its
    required QuickTime. In addition, right click the computer desktop icon for Premiere Elements 8 and select and apply Run As Administrator.
    3. Project Specifics
    For now, import your source media into the project from the computer hard drive using the project's Get Media/Files and Folders. Leave the Elements Organizer and Albums out of the equation for now. We will circle back to it soon after we decide everything else is working as it should be.
    a. You need to set a project preset. And, that project preset should match the properties of your source media. So important to know properties of source media.
    b. When you import your source media into a project you will get a red line over its content if the project preset is not a match - either because you set the wrong one or the program does not have a match for your particular video. That red line means that you are not seeing the best possible preview of what is being played back in the Edit area monitor. To get the best possible preview, you hit the Enter key of the computer main keyboard to get a rendered Timeline (red line goes from red to green after this type of rendering). That green line over your rendered Timeline indicates that you are now getting the best possible preview. This is solely a preview thing. Longer story, but I will leave it at that for now.
    c. Check Edit Menu/Preferences/Scratch Disks to assure that those Scratch Disks are being saved to a computer hard drive location with enough free space to accept them. Make sure that you do not have pile ups of previews files, conformed audio files, and conformed video files.
    See Local Disk C\Documents and Settings\Owner\My Documents\Adobe\Premiere Elements\9.0
    Never move, delete, or rename source files after they have been imported into a project which has been saved/closed. Otherwise, nasty media disconnect problems. You have only copies of media in Premiere Elements. The originals are on the hard drive, and the project must trace back to the originals where they were at import.
    Based on the above, try to start a new project. But, let me know ahead of time what you will be importing into the project. I am looking for
    Video
    video compression
    audio compression
    frame size
    frame rate
    interlaced or progressive
    pixel aspect ratio
    If you do not know, we could try to get that type of information from knowing the brand/model/settings for the camera that recorded the video.
    Photos
    Pixel dimensions and how many photos?
    Lots and lots of details, but eventually they all mellow into one workflow that you can customize for your projects.
    Please do not hesitate to ask questions or to ask for clarification. We can go at whatever pace you feel comfortable with.
    ATR

  • Where is the file button on itunes, i am trying to do this File   LIbrary Organize Library Consolidate Files

    I cannot find the file button to do this for the old ipod library and new library to work togetherFile >  LIbrary > Organize Library > Consolidate Files

    Press the CTRL+B keys and the top bar menu will appear. File/Library/... etc. is on that menu.

  • Help tracking down a file descriptor leak under java 6

    I have a large application I work on that runs fine under java5 (apart from possibly the latest update) but running under java 6 results in file descriptors used for TCP sockets being leaked.
    I'm testing this under FreeBSD 6 (both i386 and amd64) using diablo JDK and a port build jdk-1.6.0.3p3 but I have had reports from other users of exactly the same issue under various linux distributions. There are some reports that going back as far as 1.6.0b5 will resolve the issue but no later version works and a few reports that the latest 1.5 updates have the same issue.
    This application is using standard IO so Socket/ServerSocket and occasionally SSLSocket, no NIO is involved. Under the problem JDKs it will run for a while before available FDs are exhausted and then fall over with a "too many open files" exception. So far I have been unable to recreate the situation in a simple testcase and the fact it works fine under earlier JDKs is really causing me issues with deciding where to look for the issue.
    Using lsof to watch the FDs that are leaked I see a steadily increasing number shown in the following state:
    java 23438 djb 54u IPv4 0xffffff0091ad02f8 0t0 TCP *:* (CLOSED)
    java 23438 djb 55u IPv4 0xffffff0105aa45f0 0t0 TCP *:* (CLOSED)
    java 23438 djb 56u IPv4 0xffffff01260c15f0 0t0 TCP *:* (CLOSED)
    java 23438 djb 57u IPv4 0xffffff012a2ae8e8 0t0 TCP *:* (CLOSED)
    If these were showing as say (CLOSE_WAIT) then I would understand where they are coming from but as far as I understand the above means the socket has been fully closed but the FD simply hasn't been released. I'm not an expert on the TCP protocol however so I may be wrong here.
    I did try making the application set SoLinger(0,true) on all sockets which of course made all connecting clients think the connection was aborted rather than gracefully closed but even with this setting the FD leak persisted.
    I've gone as far as looking at what I think are the relevant parts of the src for both JDK versions I am using but there are very few changes and nothing that obviously looks linked.
    I'm fully prepared to spend a lot of time looking into this and I'm sure I'd eventually find the cause but if anyone here already knows what the answer may be or can simply give me a nudge in the best direction to look I would be very grateful.

    After weeks of dancing around the issue for weeks, we narrowed it down to garbage collection. If we put System.gc() to run periodically , file descriptors get garbage collected properly . I've tried playing with the settings by using XX:+UseConcMarkSweepGC which seems to help a great deal while system is under stress. However when there is light activity.. the file descriptors grow again and eventually bring everything down.
    Any clues ? is there any way to make gc to perform full collection more often ?
    pls whelp !!!

  • File descriptor leak in socket programming

    We have a complex socket programming client package in java using java.nio (Selectors, Selectable channel).
    We use the package to connect to a server.
    Whenever the server is down, it tries to reconnect to the server again at regular intervals.
    In that case, the number of open file descriptors build up with each try. I am able to cofirm this using "pfile <pid>" command.
    But, it looks like we are closing the channels, selectors and the sockets properly when it fails to connect to the server.
    So we are unable to find the coding that causes the issue.
    We run this program in solaris.
    Is there a tool to track down the code that leaks the file descriptor.
    Thanks.

    Don't close the selector. There is a selector leak. Just close the socket channel. As this is a client you should then also call selector.selctNow() to have the close take final effect. Otherwise there is also a socket leak.

  • Where is the file that contains info on previous session info on a Mac?

    Where is the file that contains info on previous session info on a Mac? I would like to restore several windows and tabs I had open earlier, but the restore previous session menu item does not appear to be available. I had to install and use an older version of Firefox (3.6) to access a website (Fedtraveler.com) that is not compatible with Firefox 6 and is seems to have cleared out the previous session information. I thought I would use Mac OSX Time machine feature to restore the Firefox file where this the previous session info is kept but I don't know what it is called nor how to find it.

    That is the file sessionstore.js in the Firefox Profile Folder.
    *http://kb.mozillazine.org/Profile_folder_-_Firefox
    *http://kb.mozillazine.org/sessionstore.js
    *Help > Troubleshooting Information > Profile Directory: Open Containing Folder

  • Where is the File 'Tropical_7.tga'?

    A few days ago I created a project using "beachresort_title" under Titles & Text > Travel > Beach Resort.
    The title seems to work as expected, however every single time I open the project file I get this window ("Where is the File 'Tropical_7.tga'?") where I am supposed to browse to this TGA file.
    It seems the project file should know where it is. But I also searched my computer high and low and can't find it.
    Why is this happening and how to fix ?
    Thanks,
    Simon

    Simon
    Premiere Elements 12 does not support .tga files which were often used in Title Templates in much earlier versions of Premiere Elements.
    From your prior threads, you appear to be working with Premiere Elements 12 in Windows 7 64 bit. So, it is curious why you should be getting "Where is the file Tropical_7.tga?" when you select Titles & Text/Travel/Beach Resort.
    Is there a blue pan at the top right corner of the thumbnail for the Beach Resort choice in the Premiere Elements display of title templates? If so, right click that blue ban and select download now. Does that action solve the problem in any way? If not, then
    Let us do this to troubleshoot...
    1. Look for the file beachresort_title.png in the following path
    Local Disk C
    Program Data
    Adobe
    Premiere Elements
    12.0
    Online
    Title Templates
    All_Lang
    Travel
    Beach Resort
    and in the Beach Resort Folder you should find the beachresort_title.png file. Is it there? Could you post a screenshot of what you find in that Beach Resort folder? If not, then just post what you find there by name.
    We will base the next phase of the troubleshooting based on your reply. More later.
    Thanks.
    ATR

  • "Where is the File?" Window

    When you open an existing Premiere CS4 project and it fails to find a file, a "where is the File?" dialogue box opens.  This contains a very useful check box "Display only exact Name Matches".
    This worked perfectly with CS4.1, but, for me, it no longer works now I have updated to CS4.2.1.  This is a nuisance!
    Is it just me, or is this feature broken now?

    No worries!  You just got me hoping for a while there.
    I tend to have sets of clips named sequentially, so I have to be careful when this box comes up.  I have had some odd results when I have clicked on the wrong file.

  • Where is the file when you export from share to you tube?

    1. where is the file when you export (share) to you tube?
    I want to use the moivie again in another movie or DVD menu or just to save it etc. I cant't find the location after uploading to you tube.
    The only way to this can not be "export to media" or devices and from there to you tube?
    2. Does it make any differances for the quality on you tube wich way you choise?
    thanks, bruce

    Yes, i found it there. In fact; a logic place...
    The second q. means the way you load upo; dirtectly from the menu share to you tube of first make a QT and from there to the sky.
    I quess there must be no differance but you never know...
    Thanks again.

  • Where is the file i/o located (File Dialog Function no Longer Support Datalog Files)

    Where is the file i/o located ?
    This is my previous post 
    File Dialog Function no Longer Support Datalog Files

    Please stick to your original post.
    The one where the question was already answered. Twice.

  • PE4 "Where is the file" keeps coming up

    On a slideshow that I created in Photoshop Elements 6 and saved as a wmv file then finished with music and credits and bonus clips in Premier Elements 4, keeps saying "Where is the file IMG 123 jpg" I have gone back to Photoshop to see what is missing in my slideshow because I did recently change the name of some photos...BUT, I changed them in photoshop so that I could avoid this problem.
    When I open the slideshow in photoshop, it doesn't tell me something is missing. I saved it again as wmv to be sure I have a clean copy, but it still pops up missing in premier.
    If there is a way to see which picture it is saying is missing while in Premier, that will be helpful. I have done a search in my computer for this file, but can't find it. It seems to have been either moved or deleted because I see the photo number before the one that is missing.
    How do I either see the picture they are talking about or how can I find the missing file.
    Thank you

    Hi, Kathy--
    Since version 5, Photoshop Elements has incorporated into its workflow a slideshow interchange format, which sends the slideshow to Premiere Elements at full quality. You can even break the file apart in Premiere Elements and continue to work with the native photos!
    It only works with matched versions, however. Which means Photoshop Elements 5/Premiere Elements 3; Photo Elements 6/Premiere Elements 4; Premiere and Photo Elements 7.
    To use it, just select the option to Send to Premiere Elements from the Photo Elements Slideshow Creator. (I do recommend, for best results, that all of your photos are no larger than 1000x750 pixels though.)
    There's much more information and step-by-step instructions in my Steve's Tips article in the members area at Muvipix.com.
    http://muvipix.com/products.php?subcat_id=7

  • When backing up ipad to PC where do the files go?

    When backing up ipad to PC where do the files go? I have 44 GB of info on my ipad and it only took about 5 minutes to backup, I do not see it on my computer. I shut my cloud off because I don't like paying for space monthly when I have so much

    Windows Vista, Windows 7, and Windows 8:\Users\(username)\AppData\Roaming\Apple Computer\MobileSync\Backup\
    To quickly access the AppData folder, click Start. In the search bar, type %appdata% and press Return.
    Hope this helps.

  • Wdfdevice.h is missing some wpp annotations. Where is the best place to report this?

    I am trying to use the WPP enum annotations in wdfdevice.h but found that many of the enums that are declared with CUSTOM_TYPE in wdftraceenums.h are not annotated with "begin_wpp enum" so the WPP generation step fails.  I'm actually
    building with WDK 1.9 but i checked the include files in 1.11 and 1.13 and they have the same issue.
    The following enums are not annotated in wdfdevice.h but listed in wdftraceenums.h:
    WDF_STATE_NOTIFICATION_TYPE
    WDF_POWER_POLICY_S0_IDLE_CAPABILITIES
    WDF_POWER_POLICY_S0_IDLE_USER_CONTROL
    WDF_POWER_POLICY_IDLE_TIMEOUT_CONSTANTS
    WDF_POWER_POLICY_SX_WAKE_USER_CONTROL
    WDF_POWER_DEVICE_STATE
    WDF_DISPATCH_IRP_TO_IO_QUEUE_FLAGS
    WDF_SPECIAL_FILE_TYPE
    WDF_DEVICE_IO_TYPE
    WDF_FILEOBJECT_CLASS
    WDF_DEVICE_FAILED_ACTION
    WDF_RELEASE_HARDWARE_ORDER_ON_FAILURE
    WDF_REQUEST_TYPE WDF_REQUEST_TYPE
    WDF_POWER_POLICY_IDLE_TIMEOUT_TYPE
    WDF_REMOVE_LOCK_OPTIONS_FLAGS
    Where is the "right" place to report this to MSFT?

    You are completely correct, It seems the CUSTOM_TYPE declarations in wdftraceenum.h are enough. The compile error I got was because I left a commented out line as one of the parameters to my TraceEvents call which apparently the preprocessor didn't like.
    Thanks,
    Eric

  • HT4854 where is the file I downloaded? I cannot always download 4 Gigs again. Too costly here in South Africa

    where is the file I downloaded? I cannot always download 4 Gigs again. Too costly here in South Africa

    If you haven't run the installer yet, it is sitting in your /Applications folder. If you have run it, I'm afraid its already gone. When you run the installer, it self deletes.
    To avoid this, you have to make a copy of the installer.app BEFORE you install (in other words, after the download completes and the installer app automatically starts, quit it, then go to /Applications and copy 'Install Mountain Lion.app').

Maybe you are looking for

  • Can I use the Apple VGA to DVI adapter to connect a PC to a DVI monitor?

    Hi Any idea of the Apple VGA to DVI adapter would work to connect a PC's VGA output to a DVI monitor? Is it a simple pass through?  Or are there drivers needed.

  • Recreate or Rebuild a new iTunes database

    I have found several people need help recreating or rebuilding their databases. This is NOT the same thing as recreating a music library, this is a deeper issue. I discovered that by tricking iTunes into thinking you are starting it for the first tim

  • TS2972 Home Sharing Issue - Help!

    I can view the library in the left hand pane; however, when I select it will not load the music.  It states "Loading "XXXXX Library" and then defaults to the music library.  Can you please help! 

  • How to cut and paste from/to a canvas?

    Could someone refer me to a documentation or tell me how I can cut/copy from or paste to a Canvas? In terms of creating a blackboard on which to draw, should I use a Canvas or is it better if I went with a JPanel settting editable to true? Thx!

  • Drop a table rule form stream

    Hi Experts, I use oracle 10GR4 for schema level stream in 32 bit window. I just a table rule in stream. but i found that source_database name is whols stream I use I want to use SALEHQ.XXXXX.com to replace SALEHQ . I do not hert exist stream system.