Resources freed on JVM Exit?

When I exit the JVM due to a RunTimeException thrown part way thru
constructing an object that has acquired some resources (like inputStreams for instance), do the resources get closed/cleaned up by the JVM during it's exit or have I left these resources tied up permanently?
I'm very clear that I must cleanup the resources myself if dealing with checked Exceptions that I don't translate into a JVM exit.
Thanks in advance for any help.

Thanks for the replys. I'm getting out of this that
a RunTimeException
caused exit of the JVM does not gaurantee cleanup of
stream resources
in particular. Correct?Depends what you mean by cleanup. All the resources obtained from the OS will be returned. There's no guarantee any streams will be flushed though.
wrt finally, it is my understanding this execution
gaurantee applies only to checked exceptions and not
to RTEs? Is this correct?You could test your assumption very easily and see for yourself, but no, that's not correct.
Finally will always be executed unless the thread terminates--e.g. by System.exit, an untrapped signal, etc. Break, continue, throw, return in try or catch all transfer control to finally.

Similar Messages

  • Solaris: memory not freed after JVM exits - why?

    Hi all,
    A client of ours has a Java application that appears to leak memory. Yawn, shrug.
    However, when the application and the JVM exit, some memory still remains missing, as evidenced by vmstat.
    On average, per run of the application 67 MB of memory and 95 MB of swap space 'disappears', eventually rendering the machine unusable. The only way to get the memory back is to reboot the machine.
    This baffles me; I'd expect the JVM to return all memory to the free list when it exits.
    System: SunOS 5.10 Generic_137111-01 sun4u sparc SUNW,Sun-Fire-15000, 32 GB physical memory.
    java version "1.5.0_05"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
    Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_05-b05, mixed mode)
    Java is invoked with:
    java -server -d64 -Xmx20G -Xms20G ...
    Has anyone seen this phenomenon before? If so, do you know what causes it? And better yet, is there a known solution for it?
    Thanks!
    Mark

    The old JVM is not my choice. My client has several Java applications running and currently doesn't have the manpower to do the retesting required when employing a newer JVM.
    I have asked the supplier of the offending program whether it will run with Java 6. They are currently looking into it.
    Mark

  • Error code 143 on JVM exit

    Hello,
    I have a program (with multiple threads, running under MS-Windows) which works fine almost all the time.
    In one case, it terminated unexpectedly, and the exit code (via ERRORLEVEL) is 143.
    There are no other outputs in order to diagnose the problem.
    I would like to know what the error code 143 exactly means.
    Can anybody give me an advice?
    Regards,
    Sabrina Werscheid

    Hello!
    I hope people there is reading old posts too. I have the same problem with code 143. JVM exits unexpectedly, but I believe it is specific block of code which acts differently. I`m trying solution with -Xrs switch, but I`m sure I have no JNI and there is no System.exit() in code at all. Also I know there is no external processes which asks JVM to close.
    I have running special FIT tests in child-jvm as ANT task. The exiting is ANT task, not my FIT tests, but at the same time this is not happening on any other processes.
    I can`t found any references about "Internal field must be valid". What does it mean? What and where to search for problem?
    Any other ideas?
    Using JVM 1.5.14

  • Is is possible to call a function or method before JVM exits ??

    Hi All,
    Is is possible to call a function or method before JVM exits where System.exit() is used.
    I am calling a program where System.exit is used. i need to call a function before the JVM exits.
    Please help me.
    Thanks,
    J.Kathir

    How to call the method ? Did i have to call the shudown hooks method in my main class ?
    Is it possible to have in subclass?
    is the below code is correct ? i am calling a class before System.exit is called....
    java.lang.Runtime.getRuntime().addShutdownHook(...My Own Class()....)

  • Eclipse failing to start - JVM Exit code 1

    Hello
    Apologies if this issue has already been posted.
    I am seeing that my Eclipse IDE is crashing everytime I try to start it, with JVM exit code 1.
    FYI, my version of java is:
    $java -version
    java version "1.5.0_12"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_12-b04)
    Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_12-b04, mixed mode)
    I am running it on openSuse 10.3 x86_64.
    The error I get is:
    JVM terminated. Exit code=1
    /usr/bin/java
    -Dosgi.requiredJavaVersion=1.5
    -Xms40m
    -Xmx256m
    -jar /home/suman/downloads/test/eclipse/plugins/org.eclipse.equinox.launcher_1.0.1.R33x_v20080118.jar
    -os linux
    -ws gtk
    -arch x86_64
    -showsplash
    -launcher /home/suman/downloads/test/eclipse/eclipse
    -name Eclipse
    --launcher.library /home/suman/downloads/test/eclipse/plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.0.3.R33x_v20080118/eclipse_1023.so
    -startup /home/suman/downloads/test/eclipse/plugins/org.eclipse.equinox.launcher_1.0.1.R33x_v20080118.jar
    -exitdata 348015
    -vm /usr/bin/java
    -vmargs
    -Dosgi.requiredJavaVersion=1.5
    -Xms40m
    -Xmx256m
    -jar /home/suman/downloads/test/eclipse/plugins/org.eclipse.equinox.launcher_1.0.1.R33x_v20080118.jar
    Any help would be much appreciated.
    Thanks
    Debz.

    Thanks.
    But I was wondering what is JVM EXit Code 1 ? Hoping its not something to do with CLASSPATH settings or anything like that.
    Rgds
    Debz.

  • File close on JVM exit

    See the following code:
    import java.io.*;
    public class Test {
            public static void main(String[] args) throws IOException {
                    PrintWriter pw = new PrintWriter(new FileWriter("test.txt"));
                    pw.write("hi");
    }This code does not close pw, hence no data is written to test.txt. To me,
    this does not make sense, because I believe that JVM surely knows what
    files are opened. Thus it wouldn't be difficult for JVM to close all files
    that are opened but not closed until user application exit.
    But, JVM does not close pw, and result in loss of data. This behavior
    would make sense if I were writing apps w/ C or C++ because those
    languages give much freedom to programmers such that people can do
    whatever they want. Java, on the other hand, has the philosophy of
    easy of use and safety, I believe.
    Does anybody know why JVM does not try to close pw?
    Sincerely,
    Minkoo Seo

    Thank you for the comment!
    The JVM is not an operating system it is a program.
    When the JVM exits, all the files opened by the JVM
    (or any other program) are closed by the real
    operating system. That doesn't include calling
    flush() or close(), which only the JVM can do and
    only if it GCs the object, which it may not do.I think JVM is actually a layer which exists right above the
    operating system and acts like a 'virtual machine.'
    Thus, like I said, I believe that the virtual machine maintains
    file descriptors like all other operating systems do.
    And ejp suggest that JVM is nothing but a program which
    makes sense also.
    So I wonder whether JVM actually maintains file descriptor
    table (or linked list) or not. If it does, JVM is irresponsible
    because it does not take care of destruction of file descriptor
    table. If not, that's okay. I'm just curious.

  • When does the JVM exit ?

    I am curious as to what could be the reasons when the JVM exits.Googling didn't give me much relevant links (my bad,may be !!).
    However the JLS states :
    A program terminates all its activity and exits when one of two things happens:
    1. All the threads that are not daemon threads terminate.
    2. Some thread invokes the exit method of class Runtime or class System and the exit operation is not forbidden by the security manager.
    Now,Are there any other reasons apart from the above that may result in a JVM to exit ? I would appreciate any pointers.
    Thank you for your consideration.
    Edited by: punter on Jan 4, 2010 4:14 AM

    Well, you already found the "normal" ways of exiting the JVM.
    punter wrote:
    Now,Are there any other reasons apart from the above that may result in a JVM to exit ? I would appreciate any pointers.It can also halt unexpectedly: crashing. By the very nature of crashes it's hard to define how exactly they happen. But they can happen.
    I assume that you could also call exit() (the C function) from native code, the JVM probably couldn't do much about that.

  • When does the JVM exit and deleteOnExit();?

    I developed a JSP that queries a database, displays the results in a browser, and writes the results to the server as a file. While the user is viewing the JSP, they can click on a download link to save the file that was written to the server. Everything works fine!
    I would like to delete the file that was written to the server (to save space), however, I can't delete the file until the user is finished viewing the JSP. I need some help concerning this method: java.io.File.deleteOnExit() the API states:
    "Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates. Deletion will be attempted only for normal termination of the virtual machine, as defined by the Java Language Specification (12.9)."
    If I use this method, When does the JVM exit? I tested it in my home environment using Tomcat and the file was deleted when I stopped Tomcat. If I run this on a web server, does the JVM ever exit? If so when?
    Thanks
    --Scott

    The JVM stays active so long as the Java based webserver (or the servlet engine if your webserver is connected to one) is up. Only when you shutdown your server will the VM terminate. (Similar to what you observed with tomcat)

  • JVM exit handler -  for jvm invoked thro' native C

    complicated, atleast for me :) where do I find if JVM installs any exit handlers when invoked through native C app.
    OS -> HP UX 11
    java -version ->
    java version "1.4.0.02"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0.02-021031-18:00)
    Java HotSpot(TM) Server VM (build 1.4 1.4.0.02-021031-19:15-PA_RISC2.0 PA2.0, mixed mode)
    Although jvm used is HP's hotspot, behaviour seems to be generic, so any directions are appreciated.
    In my case JNI based native shared object (on ux) is being used as a pluggin for comm with microsoft SQL2k.
    A daemon loads the pluggin (shl_load) -> transaction -> unloads (shl_unload) pluggin.
    For each tran I need to create a new JVM instance and later distroy it as it is not possible to multiple times create and distroy JVM in same process space (as encountered)
    LD_PRELOAD=.../libjvm.sl
    start the daemon( basic signals masked)
    Parent -> fork() a child process and wait for its exit status.
    Child -> Load JVM and execute reqd method
    Child -> unload JVM
    Child -> exit() the child process
    Parent ->Check the child process exit() code and carry further processing.
    Sometimes child does not exit cleanly. Even after exit() child process can be seen in process table and parent wait()'s idefinetly for child exit code.
    gdb ouput of child preocess
    #0 0xdd28ca38 in os::report_fatal_error () from /opt/java1.4/jre/lib/PA_RISC2.0/server/libjvm.sl
    #1 0xdd28dc48 in os::handle_unexpected_exception ()
    from /opt/java1.4/jre/lib/PA_RISC2.0/server/libjvm.sl
    #2 0xdd296c50 in os::Hpux::JVM_handle_hpux_signal ()
    from /opt/java1.4/jre/lib/PA_RISC2.0/server/libjvm.sl
    #3 0xdd293adc in os::Hpux::signalHandler ()
    from /opt/java1.4/jre/lib/PA_RISC2.0/server/libjvm.sl
    #4 <signal handler called>
    #5 0x7e5e6134 in ?? ()
    #6 0xc03c6fbc in __niamHelper () from /usr/lib/libCsup.2
    Can any one tell me what exactly is happening ?
    If I call [b]_exit() instead of exit() everything works fine.

    Thnx a lot,
         Finally I was able to locate atexit()'ed function which was causing the problem (setting br at exit() was not working, execution straightway stopped at #0)
    (gdb) thr 1
    [Switching to thread 1 (system thread 17555)]
    (gdb) bt
    #0 0x7e6224e0 in epc_exit_handler () from /citisafe/users/yogiraj/cs35/dll/ora_tcp.sl
    #1 0xc03c6fbc in __niamHelper () from /usr/lib/libCsup.2
    #2 0xc03c7110 in niambody () from /usr/lib/libCsup.2
    #3 0xc03c721c in _niam () from /usr/lib/libCsup.2
    #4 0xc016fe20 in exit () from /usr/lib/libc.2
    #5 0xc4f0c364 in sql_exec_custStrProc () from /citisafe/users/yogiraj/cs35/lib/libtcsql.sl
    #6 0x7ec0c9f4 in exec_ext_mgmt (p_ExtCredentials=0x7edf2878)
    at /citisafe/users/yogiraj/cs35/c/sql_app.c:251
    #7 0x9620 in adm_process_rec ()
    #8 0x8bc8 in process_pwd_requests ()
    #9 0x8684 in adm_do_ext_sync ()
    #10 0x7f5c in main ()
    Oracle client lib was the culprit.     Daemon is basically a 'C' daemon which loads pluggins for communication with various DB's including Oracle, Sybase, MS SQL etc and later unloads them on completion.
    Ora lib libclntsh.sl installed "epc_exit_handler", eventhough we had shl_unload()'ed oracle pluggin earlier the handler refrence was still around. Later when process exit()'ed may be static dealloaction mech panicked.
    Above exit() handler execution even after unloading of Oracle libs seems to be a known bug and work around suggested is to LD_PRELOAD=%ORALIB/libclntsh.sl. After LD_PRELOAD'ing exit() works fine.

  • JVM Exit code=11

    Hello All!
    On linux red hat 9 where start IBM WebSphere Studio 5
    happend error:
    JVM terminated, Exit code=11
    Where I find documentation about it?
    With best regards,
    Valery Bondarenko

    can you help me in this:
    i need a code [how to exit in java programing-in MS.DOS.
    Thanks..
    SAMIS                                                                                                                                                                                                       

  • Jvm exit code 128

    I'm running a memory / cpu and thread intensive program that's using JIntegra for a com bridge. We're hammering our windows 2003 server machine with 4 gigs of ram pretty hard.
    We're also using the java service wrapper to launch our java process. Under this heavy load I see this:
    JVM process exited with a code of 128, setting the wrapper exit code to 128.
    What is this exit code telling me?

    test reply
    Edited by: lhyang on Jun 3, 2008 3:30 PM

  • JDialog, dispose, and JVM exit

    Why is it that running this code: import javax.swing.JDialog;
    public class Temp {
         public static void main(String args[]) {
              JDialog dialog = new JDialog();
              dialog.setVisible(true);
              dialog.dispose();
              dialog = null;
    }does not cause the JVM to terminate, but running this code: import javax.swing.JDialog;
    public class Temp {
         public static void main(String args[]) {
              JDialog dialog = new JDialog();
    //          dialog.setVisible(true);
              dialog.dispose();
              dialog = null;
    }does? What I want to happen is to cleanly dispose of the JDialog without terminating the JVM --- thus, System.exit(0) is not a viable solution here (unlike the similar JFrame problem).

    Use the setDefaultCloseOpration() thus:
    <code>
    import javax.swing.JDialog;
    public class Temp {
         public static void main(String args[]) {
              JDialog dialog = new JDialog();
         dialog.setVisible(true);
              dialog.dispose();
    dialog.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
    </code>

  • UI disappears and the JVM exits

    I have a application running. It runs with a max 512MB vm memory setting. When i select a particular option which in turn spawns another JVM and start one more app. The memory used by the first JVM crosses the specified limit and then the GUI grays out first(components in the frame disappear) and then the entire GUI disappears and both the JVM's are killed subsequently.
    I don't call System.exit() anywhere in my code.
    Is it the OS that kills the JVM by any chance?
    I am running my app on Win2K SP 2.
    Would be really helpfull if u anybody out there give me some pointers to this problem.
    Thanx in advance..:)

    Did you ever find a solution to your problem? We're having a similar problem w/GUIs disappearing w/o a trace. The lack of error messages reminded me of when we had a problem with the console buffer being filled w/messages from a C++ subprocess launched from within our Java GUI. We had to add code to eat the messages from stdout and stderr, and I'm wondering if we're now eating a stack trace or VM panic message.

  • JVM exit on connect

    Hello. I'm having an issue where something with my connections get corrupted and it kills my sql developer. If I reinstall SQL Developer and recreate (not import) the connection it will work again.
    Upon inspecting the exported connections, I noticed the jdbc connection string was changed from jdbc:oracle:thin:@... to jdbc:oracle:oci8:@... I then was able to recreate this when I edit the connection after creating it. I originally set this up with a JDBC connection string but when I went to edit the connection, it shows up under the TNS and not advanced tab. Here is the connection exported upon creation:
    <connections>
    <connection>
    <ConnectionType>JDBC</ConnectionType>
    <DeployPassword>false</DeployPassword>
    <user>devanon1</user>
    <ConnectionName>Devanon1</ConnectionName>
    <URL>jdbc:oracle:thin:@<...></URL>
    <JdbcDriver>oracle.jdbc.driver.OracleDriver</JdbcDriver>
    <PWD>
    <![CDATA[0592FB1AFDF939C8FD874C0F20276B673E8880959FB3E87FD2]]>
    </PWD>
    <ORACLE_JDBC_TYPE>thin</ORACLE_JDBC_TYPE>
    </connection>
    </connections>
    And then after editing
    <connections>
    <connection>
    <ConnectionType>JDBC</ConnectionType>
    <DeployPassword>false</DeployPassword>
    <user>devanon1</user>
    <ConnectionName>Devanon1</ConnectionName>
    <URL>jdbc:oracle:oci8:@<...></URL>
    <JdbcDriver>oracle.jdbc.driver.OracleDriver</JdbcDriver>
    <PWD>
    <![CDATA[05EF2C61FA876C70D514969F89F14B8CE945BDFCEB485CA94D]]>
    </PWD>
    <ORACLE_JDBC_TYPE>thin</ORACLE_JDBC_TYPE>
    </connection>
    </connections>
    I'd include console output and the JVM dump when it crashes but it would make this message too verbose and the issue is clearly defined.
    Sorry if this post exists elsewhere but I couldn't find it via search and have already spent enough time battling this issue.

    This is mention in the forum but no direct topic in the subject line to search on. See this post Re: 1.1 - Issues
    -kris

  • JVM, exit codes and Windows 98

    Has anyone got System.exit(integer) to return a value other than 0 under Windows 98?
    Regardless of what integer I enter as an exit code, java.exe always seems to return 0. This does not seem to be the case under Windows NT, where the correct exit code is passed back.
    Is anyone aware of this problem/found a workaround?

    How are you checking the exit value under 98?

Maybe you are looking for

  • Getting paper sizes list of currently installed printer

    plz help me out i have to fetch the paper sizes supported for currently installed printer ,may it will be possible throw MediaSize class ? ASAP Thanks

  • URGENT : ArrayIndexOutOfBoundsException

    Hi, I have a very annoying problem when trying to connect to a database : - I can connect to this database with SQL*Plus without any problem. - I wrote a simple Java program to connect to a database and perform a SELECT which works on a local databas

  • Problems after updating to ios6

    Just updated my 3GS to ios6 and cannot send emails or connect to my vehicle's bluetooth. My email states my email address has been "rejected by server". My passwords and ID's are correct. Any ideas what I'm doing wrong?

  • I can't access messages or facetime from my mac

    I've been using messages and facetime on my macbook air for almost a year now. I am currently running OS X Mountain Lion 10.8.4. Recently I've had trouble getting onto facetime and messages from my mac. I have no problems getting on either from my iP

  • Confirmed Bug in Siri - Texting a character not found in 7-bit ASCII Table Causes SMS to Fail

    I am 99.9% certain I have singlehandedly discovered and solved a bug in Siri that causes SMS messages to fail (without a failure notice, i.e. red exclamation mark). This problem confounded me for several weeks. (Note: This issue does not affect iMess