Avoiding system.exit(0)

Hi
I am using an external .jar file in my java program for parsing a file. My problem is that its main method has System.exit statement in the end i.e after parsing it exits the application. So when i use it my application also gets terminated. I have decompiled it and the only accessible method is main method. Is there any way to avoid this system.exit(0) ?

EJP wrote:
You can run it under a SecurityManager and a .policy file which doesn't grant that permission.I am trying to overrite securityManager functions:
like:
private static void forbidSystemExitCall() {
    final SecurityManager securityManager = new SecurityManager() {
            @Override
      public void checkPermission( Permission permission ) {
                System.out.println("persmiion");
        if( "exitVM".equals( permission.getName() ) ) {
         throw new SecurityException("System.exit attempted and blocked.");
            @Override
      public void checkExit(int exit)
          super.checkExit(exit);
          throw new SecurityException("System.exit attempted and blocked.");
    //System.setSecurityManager( securityManager ) ;
  }and calling above code as:
             try
                    forbidSystemExitCall() ;
                    try
                       Main.main(strings);
                    catch( ExitTrappedException e )
                    finally
                      enableSystemExitCall() ;
               catch ( Exception ex)
                   System.out.println("error calling main method");
                   ex.printStackTrace();
               }but above code is not working as i requried.
Or if you have stuff to do on exit you can add shutdown hooks, see java.lang.Runtime.i could not understand it, please kindly can you explain little bit more... I have not play with java security before.
BR
Umer

Similar Messages

  • Catching System.exit() or How to avoid System.exit() - Third Party Tool ???

    Hi All,
    I am using a third party tool which is internally calling System.exit sometimes and my application
    got terminated most of the times.
    It is happening always when i call a particular method of that third party tool.
    Is there any way to catch or avoid the System.exit while using the particular method?
    I need this urgently...Please kindly help.....
    Thanks,
    J.Kathir

    There's a fair bit to it, and you should refer to the appropriate java Tutorials. Bascially you create a .policy file and install a sercurity manager with:
    System.setSecurityManger(new SecurityManager());The policy file grants a set of permissions to various "code sources", basically each codesource is a classpath entry. You could grant "AllPermissions" to your own code, and a more restricted set of permissions to the application you're running. But you can't subtract permissions, i.e. you can't say "this code can do anything except call System.exit().
    I doubt this is going to provide you with a good solution. It's tiresome to set up, and when the client app called System.exit it would crash, which might not result in a clean status.
    I'd consider if you should be using this client app in the same JVM, rather than creating a subordinate JVM using Runtime.exec.

  • System.exit(0) - Avoid JVM termination

    Hi,
    Is there any possibility to avoid JVM termination when we use system.exit(0).
    I have created my own SecurityManager.
    public class MySecurityManager extends SecurityManager {.....}, and I can able to get S.O.P at public void checkPermission(final Permission permission) {..} and public void checkExit(int status) {..} in SecurityManager , My code in main() is
    MySecurityManager mySM = new MySecurityManager();
              System.setSecurityManager(mySM);
    System.out.println("Before......");
    System.exit(0);
    System.out.println("After......");
    i cant able to get SOP "After.....",
    Is there any possibility to raise exceptions when i introduce exit(0) in my java file.....? or Is there any possibility to avoid JAVA termination when i use System.exit(0).
    Thankx in Advance

    uh, System.exit is defined as the command to
    terminate the JVM. You can avoid that by not calling
    System.exit...Or do just what the OP tried to do.
    class Test {
         public static void main(String args[]) throws Exception {
              System.setSecurityManager(new ExitHandlingSecurityManager());
              System.out.println("Before");
              try {
                   System.exit(1);
              } catch (SecurityException e) {
                   System.err.println("Couldn't exit the VM: " + e.getMessage());
              System.out.println("After");
    class ExitHandlingSecurityManager extends SecurityManager {
         @Override
         public void checkExit(int arg0) {
              throw new SecurityException("You aren't allowed to terminate VM");
    }Prints:
    Before
    Couldn't exit the VM You aren't allowed to terminate VM
    After
    Kaj

  • Exit from a Frame without resorting to System.exit()

    This is driving me nuts.
    I've got a really simple problem, actually... I've got a Frame and I'm trying to get rid of it so my application will exit.
    Though using System.exit() seems to be the most common way to get an application to exit, I'd prefer to avoid going that route. My program uses multiple threads, and I want to give them all a chance to exit gracefully before the application exits, as opposed to terminating them all quite suddenly. All the threads monitor a boolean value, "exiting", and terminate, after some cleanup, when the variable is set. Using join() on all the threads before using System.exit() would work, except any number of threads may be created by the program, and not all of them will be accessible by the function doing the exiting!
    If I simply omit the call to System.exit(), and remove the Frame with dispose(), the threads all shut down properly, and the program appears to have exited, except the command prompt doesn't reappear until I hit Ctrl-C.
    So I looked up the docs for the dispose() method. It was slightly different than I remembered... Obviously, that method is not the way to shut down a Frame. What is?

    So I looked up the docs for the dispose() method. It
    was slightly different than I remembered...
    Obviously, that method is not the way to shut down a
    Frame. What is?The problem is that once you use some GUI, a pool of AWT threads is created and they are not shut down, not even if there is no more GUI visible.
    Look at these other threads for some explanation on this behaviour an workarounds:
    http://forum.java.sun.com/thread.jspa?forumID=5&threadID=10901
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=122569

  • Why in COM, set smth true, stays true even after System.exit?

    I am using "Jacob" to do COM calls. When I alter the "ShowAll" property of Word.Application and I set it to true, it will then forever be true even if I exit the application AND quit the word application. If I set it to false, the same thing happens, it will always be so. The code to call/set this is:
    (NOTE: This uses classes I made to wrap the Dispatch calls)
    Word wordApp = new Word();
    Documents docs = wordApp.getDocuments();
    Document doc = docs.open("D:\\JavaProjects\\Test.doc");
    //GET VIEW
    View wordView = wordApp.getActiveWindow().getView();
    //PRINT THE VIEW PROPERTIES
    System.out.println("Show All: " + wordApp.getActiveWindow().getView().isShowAll());
    System.out.println("Show Paragraphs: " + wordApp.getActiveWindow().getView().isShowParagraphs());
    //SET THE VIEW PROPERTIES
    wordView.setShowAll(false);
    wordView.setShowParagraphs(true);
    //PRINT THEM AGAIN
    System.out.println("Show All: " + wordApp.getActiveWindow().getView().isShowAll());
    System.out.println("Show Paragraphs: " + wordApp.getActiveWindow().getView().isShowParagraphs());
    doc.close(Document.DO_NOT_SAVE);
    wordApp.quit(new Variant[] {});
    System.exit(0);The actual Dispatch calls are:
    //NO IDEA WHY THIS IS, BUT SHOWALL = TRUE IS -1, AND FALSE IS 0
    private final static int SHOW_ALL_TRUE = -1;
    private final static int SHOW_ALL_FALSE = 0;
    /** SETSHOWPARAGRAPHS **
    * Sets the property (boolean) ShowParagraphs.
    public void setShowParagraphs(boolean showParagraphs)
         Dispatch.put(this, "ShowParagraphs", new Boolean(showParagraphs));
    /** ISSHOWPARAGRAPHS **
    * Returns Boolean of whether or not this is set to show paragraphs.
    public boolean isShowParagraphs()
         return getBooleanValue(Dispatch.get(this, "ShowParagraphs"));
    private boolean getBooleanValue(Variant variantBoolean)
         //MAKE IT AN INTEGER AND GET ITS int VALUE
         int intVariant = new Integer(variantBoolean.toString()).intValue();
         //RETURN IF IS SHOW ALL
         return (intVariant == View.SHOW_ALL_TRUE);
    }I'm wondering if the problem is that I get back either -1 or 0 and if maybe that means something else?

    1: Properties persistence is not a DEFECT but a FEATURE . It was implemented in MS Word so users could change MS word WITHOUT HAVING TO DO IT EACH TIME THEY START IT UP.
    2: Don't you intialise all your variables in your code after you instanciated them ? I am sure you do so and therefore the persitence feature you described should not be annoying you at all. It is not necessary to intialise variables in the BASIC langage but that does not mean you should not do it.
    3: (-1) was chosen arbitrary by Microsoft as the TRUE value for Boolean datatype and 0 the value for FALSE when they designed Visual Basic. This is not a problem if you write code properly
    I recommend you test bool variable in any langages using the following test:
    (myBool <> 0)
    HAVE A THINK ABOUT IT
    Finally,
    you need to understand what you are working with before you complain about it.
    Argument for Argument sake is not good and if you think MS word is a bad program just don't use it. go and write your own word processor in JAVA.
    GOOD LUCK
    I WISH TO APOLOGISE FOR ANY POSSIBLE SPELLING OR GRAMMATICAL MISTAKES I COULD HAVE MADE IN THIS REPLY. ENGLISH NOT BEING MY FIRST LANGUAGE.

  • Denying system.exit in java code

    My objective is to nullifying the system.exit programmed. By goggling i learn t that this can be done by adding permission in policy file. But as far my google search i dont understand how to deny a permission. Most of them says about granting a permission. Can anyone clarify how to deny a permission.
    Steps i tried.
    Sample program: which does nothing other than calling system.exit(0) as the first line in main method.
    added the following line to java.policy file in my JAVA_HOME/jre/lib/security
    grant {
              permission java.lang.RuntimePermission "exitVM";
    Also tried adding only
    permission java.lang.RuntimePermission "exitVM";
    to the already available grant block.
    Also commented out
    //grant codeBase "file:${java.home}/lib/ext/*" {
    //     permission java.security.AllPermission;
    After that i understood that the default java policy file is java.home\lib\security\java.policy. So made all the change above mentioned there too.
    But i could not achieve it. Can any one help me on this.
    Win 2000/ Java1.4.2_12/no command line arguments while running the program.

    Welcome to the Forums.
    Please go through the FAQ of the Forum.
    You has posted your query in the wrong Forum, this one is dedicated to Oracle Forms.
    Please try {forum:id=1050}.
    Regards,

  • The ABAP call stack was: SYSTEM-EXIT of program BBPGLOBAL

    Hi
    We are using SRM 5.0. We are facing a strange problem. We are able to see the initial screen of SRM EBP in the browser. But once the user name and password are provided the system goes for a dump with the following error:
    The following error text was processed in the system SS0 : System error
    The error occurred on the application server <Server Name> and in the work process 0 .
    The termination type was: ABORT_MESSAGE_STATE
    The ABAP call stack was: SYSTEM-EXIT of program BBPGLOBAL
    <b>SM21 Log:</b>
    Short Text
         Transaction Canceled &9&9&5 ( &a &b &c &d &e &f &g &h &i )
         The transaction has been terminated.  This may be caused by a
         termination message from the application (MESSAGE Axxx) or by an error
         detected by the SAP System due to which it makes no sense to proceed
         with the transaction.  The actual reason for the termination is
         indicated by the T100 message and the parameters.
    Transaction Canceled ITS_P 001 ( )
    Message Id: ITS_P
    Message No: 001
    I just checked these threads but did not help much,
    RABAX_STATE  error after loggin into BBPSTART service in SRM 4.
    ITS_TEMPLATE_NOT_FOUND error
    Besides I tried this note: 790727 as well, still I get the same error.
    Any help would be highly appreciated.
    Thanks in advance
    Kathirvel Balakrishnan

    Hi
    <u>Please do the following steps.</u>
    <b>When you are using the Internal ITS,you need not run the report W3_PUBLISH_SERVICES.(only SIAC_PUBLISH_ALL_INT )
    ALso pls check the foll:
    -->activate the services through SICF tcode.
    > Go to SICF transaction and activate the whole tree under the node Default host>sap>bc>gui>sap>its.
    >Also maintain the settings in SE80>utilities>settings>internet transaction server-->test service/Publish. (BBPSTART , BBPGLOBAL etc)
    Table TWPURLSVR should have entries for the / SRM server line as well as gui and web server.
    Could you please review again the following steps ?
    Did you check that ICM was working correctly (Transaction -  SMICM) ?
    1-Activate the necessary ICF services
    With transaction SICF and locate the
    services by path
    /sap/public/bc/its/mimes
    /sap/bc/gui/sap/its/webgui
    2- Publish the IAC Services
    With Transaction SE80 locate from
    the menu Utilities -> Settings ->
    Internet Transaction Server (Tab) ->
    Publish (Tab) and set “On Selected
    Site” = INTERNAL.
    3- Locate the Internet Services SYSTEM and WEBGUI.
    Publish these services with the Context
    Menu -> Publish -> Complete Service
    4- Browse to http://<server>:<icmport>/sap/bc/gui/
    sap/its/webgui/! and login to the
    webgui.</b>
    Hope this will help.
    Please reward suitable points.
    Regards
    - Atul

  • How  to track System.exit(0) call

    hi there,
    how can i trace the System.exit(0) function call in my program.
    i.e as we know which class is being loaded into the jvm by overriding
    the classloader, can we similarly know when is our jvm going to be
    destroyed. here iam invoking jvm from my windows program using invocation api.
    any help is mostly appreciated.
    thanks in advance
    bye
    ramana

    Not sure I know what you are asking.
    You could create a security manager which prevents exit() from being called.
    You could replace System using the bootstrap command line option. Although if you do that you can not distribute it due to the license agreement. Once replaced you can do anything you want in the application.
    You could use Runtime.addShutdownHook() if you just want to do something when the application exits.

  • System.exit doesnt work on Sun OS 5.7 ??

    Hi, I have encountered a kind of wierd problem. I have a small application that uses System.exit when the user wants to shut down the application.
    That works fine in Windows but in Sun OS 5.7 the application just freeze.
    Im using java version:
    java version "1.4.1"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
    Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
    Would be greatful if someone could help me.
    This code is an small example of my application.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class ExitTest extends JFrame implements ActionListener {
    JButton jButton1 = new JButton();
    public ExitTest() {
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    public static void main(String[] args) {
    new ExitTest().setVisible(true);
    private void jbInit() throws Exception {
    jButton1.setText("Exit");
    jButton1.addActionListener(this);
    addWindowListener(this);
    this.getContentPane().add(jButton1, BorderLayout.SOUTH);
    public void actionPerformed(ActionEvent e) {
    this.setVisible(false);
    System.out.println("Exiting");
    try {
    System.exit(0);
    } catch(SecurityException ex) {
    ex.printStackTrace();
    ---------------------------------------------------------------------------------------------------------

    Hmm, sorry about that, my misstake, that line is still there from an erlier attempt to use windowlisteners instead ... that line should not be there ...

  • System.exit(0) closing both JFrames

    hey, ive got a problem with a JFrame
    Ive got 1 JFrame that currently holds a JMenuBar, 2 JMenus and in the 1st JMenu there are 4 JMenuItems.
    One of the JMenuItems uses an ActionListener to lauch another JFrame, but when the 2nd JFrame is finished (and System.exit(0) launches), the first JFrame closes as well. What is going on??
    code follows:
    THE MAIN JFRAME
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class realframe extends JFrame
    protected JMenuItem[] m_fontMenus;
    protected JCheckBoxMenuItem m_showPatList;
    protected JCheckBoxMenuItem m_showPatData;
    protected JCheckBoxMenuItem m_showHRGraph;
    protected JCheckBoxMenuItem m_showBPGraph;
    protected JCheckBoxMenuItem m_showTempGraph;
    public realframe(){
    super("PMS Menu GUI");
    setSize(450, 350);
    JMenuBar menuBar = createMenuBar();
    setJMenuBar(menuBar);
    WindowListener wndCloser = new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    addWindowListener(wndCloser);
    setVisible(true);
    //start Menus
    protected JMenuBar createMenuBar()
    final JMenuBar menuBar = new JMenuBar();
    //creates File
    JMenu mFile = new JMenu("File");
    //Menu 1 item 1 : : : Add Patient
    JMenuItem item = new JMenuItem("Add Patient");
    ActionListener lst = new ActionListener() //ActionListener for Add Patient
    public void actionPerformed(ActionEvent e)
    new realgui( new JFrame() );
    item.addActionListener(lst);
    mFile.add(item);
    //Menu 1 item 2 : : : Delete Patient
    item = new JMenuItem("Delete Patient");
    lst = new ActionListener()
    public void actionPerformed(ActionEvent e) { }
    item.addActionListener(lst);
    mFile.add(item);
    //Menu 1 item 3 : : : Search
    item = new JMenuItem("Search");
    lst = new ActionListener()
    public void actionPerformed(ActionEvent e) { }
    item.addActionListener(lst);
    mFile.add(item);
    //Divider
    mFile.addSeparator();
    //Menu 1 item 4 : : : Exit
    item = new JMenuItem("Exit");
    item.setMnemonic('x');
    lst = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    System.exit(0);
    item.addActionListener(lst);
    mFile.add(item);
    menuBar.add(mFile);
    //end menu item 1
    ActionListener viewListener = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    updateMonitor();
    JMenu mView = new JMenu("View");
    mView.setMnemonic('V');
    //Menu 2 item 1 : : : Patient List Toggle
    m_showPatList = new JCheckBoxMenuItem("Patient List");
    m_showPatList.setMnemonic('L');
    m_showPatList.setSelected(true);
    m_showPatList.addActionListener(viewListener);
    mView.add(m_showPatList);
    //Menu 2 item 2 : : : Data box Toggle
    m_showPatData = new JCheckBoxMenuItem("Patient Data");
    m_showPatData.setMnemonic('D');
    m_showPatData.setSelected(true);
    m_showPatData.addActionListener(viewListener);
    mView.add(m_showPatData);
    //Divider
    mView.addSeparator();
    //Menu 2 item 3 : : : HR Graph toggle
    m_showHRGraph = new JCheckBoxMenuItem("Show HR Graph");
    m_showHRGraph.setMnemonic('H');
    m_showHRGraph.setSelected(true);
    m_showHRGraph.addActionListener(viewListener);
    mView.add(m_showHRGraph);
    //menu 2 item 4 : : : BP Graph Toggle
    m_showBPGraph = new JCheckBoxMenuItem("Show BP Graph");
    m_showBPGraph.setMnemonic('B');
    m_showBPGraph.setSelected(true);
    m_showBPGraph.addActionListener(viewListener);
    mView.add(m_showBPGraph);
    //menu 2 item 5 : : : Temp Graph Toggle
    m_showTempGraph = new JCheckBoxMenuItem("Show Temp Graph");
    m_showTempGraph.setMnemonic('T');
    m_showTempGraph.setSelected(true);
    m_showTempGraph.addActionListener(viewListener);
    mView.add(m_showTempGraph);
    menuBar.add(mView); //adds the menu
    return menuBar;
    protected void updateMonitor() { }
    public static void main(String argv[]) { new realframe(); }
    THE SECONDARY JFRAME
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    public class realgui extends JDialog implements ActionListener
    JTextField surname;
    JTextField given;
    JTextField age;
    JTextField doctor;
    JTextField phone;
    Patient patient = new Patient();
    JRadioButton radiomale;
    JRadioButton radiofemale;
    public realgui( JFrame frame )
    super( frame, true );
    System.out.println("in 1");
    setTitle( "Add A New Patient" );
    setSize( 400, 250 );
    JPanel panel = new JPanel( new BorderLayout() );
    panel.setLayout( new GridBagLayout() );
    panel.setBorder( new EmptyBorder( new Insets( 5, 5, 5, 5 ) ) );
    getContentPane().add( BorderLayout.CENTER, panel );
    GridBagConstraints c = new GridBagConstraints();
    Dimension shortField = new Dimension( 40, 20 );
    Dimension mediumField = new Dimension( 100, 20 );
    Dimension longField = new Dimension( 180, 20 );
    EmptyBorder border = new EmptyBorder( new Insets( 0, 0, 0, 10 ) );
    EmptyBorder border1 = new EmptyBorder( new Insets( 0, 20, 0, 10 ) );
    c.insets = new Insets( 2, 2, 2, 2 );
    c.anchor = GridBagConstraints.WEST;
    JLabel lbl1 = new JLabel( "Surname:" );
    lbl1.setBorder( border );
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 1;
    panel.add( lbl1, c );
    surname = new JTextField();
    surname.setPreferredSize( longField );
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add(surname, c );
    JLabel lbl7 = new JLabel( "Given Name:" );
    lbl7.setBorder( border );
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 1;
    panel.add( lbl7, c );
    given = new JTextField();
    given.setPreferredSize( longField );
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add(given, c );
    JLabel lbl2 = new JLabel( "Age:" );
    lbl2.setBorder( border );
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = 1;
    panel.add( lbl2, c );
    age = new JTextField();
    age.setPreferredSize( shortField );
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add( age, c );
    JLabel lbl3 = new JLabel( "Gender:" );
    lbl3.setBorder( border );
    c.gridx = 0;
    c.gridy = 3;
    panel.add( lbl3, c );
    JPanel radioPanel = new JPanel();
    radioPanel.setLayout( new FlowLayout( FlowLayout.LEFT, 5, 0 ) );
    ButtonGroup group = new ButtonGroup();
    radiomale = new JRadioButton( "Male" );
    radiomale.setSelected( true );
    group.add(radiomale);
    radiofemale = new JRadioButton( "Female" );
    group.add(radiofemale);
    radioPanel.add(radiomale);
    radioPanel.add(radiofemale);
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add( radioPanel, c);
    JLabel lbl4 = new JLabel( "Doctor:" );
    lbl4.setBorder( border );
    c.gridx = 0;
    c.gridy = 4;
    panel.add( lbl4, c );
    doctor = new JTextField();
    doctor.setPreferredSize( longField );
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add(doctor, c );
    JLabel lbl5 = new JLabel( "Phone Number:" );
    lbl5.setBorder( border );
    c.gridx = 0;
    c.gridy = 5;
    c.gridwidth = 1;
    panel.add( lbl5, c );
    phone = new JTextField();
    phone.setPreferredSize( mediumField );
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add(phone, c );
    JButton submitBtn = new JButton( "Submit" );
    c.gridx = 4;
    c.gridy = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    panel.add( submitBtn, c );
    submitBtn.addActionListener(this);
    JButton cancelBtn = new JButton( "Cancel" );
    c.gridy = 1;
    c.anchor = GridBagConstraints.NORTH; // anchor north
    panel.add( cancelBtn, c );
    cancelBtn.addActionListener(this);
    WindowListener wndCloser = new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    addWindowListener( wndCloser );
    setVisible( true );
    public static void main( String[] args ) {
    new realgui( new JFrame() );
    public void actionPerformed(ActionEvent evt)
    if (evt.getActionCommand ().equals ("Submit"))
    Person person = new Person();
    String surnam = surname.getText();
    String give = given.getText();
    String ag = age.getText();
    String docto = doctor.getText();
    String phon = phone.getText();
    char gende;
    if(radiomale.isSelected()==true)
    gende = 'M';
    else
    gende = 'F';
    System.out.println("in 2 " + surnam);
    person.setSurname(surnam);
    person.setGiven(give);
    // person.setAge(ag);
    person.setDoctor(docto);
    person.setPhone(phon);
    person.setGender(gende);
    System.out.println(surnam + " " + give + " " + ag + " " + gende + " " + docto + " " + phon);
    person.setHistory();
    patient.add(person);
    System.exit(0);

    No, dispose() is inherited. Just replace System.exit(0); with:
    setVisible(false);
    dispose();I think that'll work in your code.

  • System.exit(0); reboots PC..........

    Hello all,
    I compiled and ran this program with no problems about 5 or 6 times as soon as I finished writing it. I walked away for about 15 minutes and tryed to run it again. The program runs fine up until the end; now, however, at the System.exit(0); line the system promptly REBOOTS.
    I am running windows XP Pro.....
    Any ideas as to what may be causing this?
    1. Take input from user for how many numbers will be in the array.
    2. Allow user to input the values 0ne by one usig for loop and break loop upon reaching
    value input from number 1(above).
    3. Make class to do linear search
    import javax.swing.JOptionPane;
    public class LinearSearch
      public static void main(String args[]) {
    SearchArrayLinear X = new SearchArrayLinear();
        String input, input2, input3;
        int array[], len, element, key;
        input = JOptionPane.showInputDialog(null,
            "How many integers do you want to input into the array? ", "INPUT",
            JOptionPane.QUESTION_MESSAGE);
        len = Integer.parseInt(input);
        array = new int[len];
        for (int counter = 0; counter < len; counter++)
        array[ counter ] = Integer.parseInt( JOptionPane.showInputDialog(null,
                                      "Input index " + counter + " into the array",
                                      "INPUT", JOptionPane.QUESTION_MESSAGE) );
       X.linearSearch(array);
    class SearchArrayLinear
    public void linearSearch( int array2[] ) {
        String input = JOptionPane.showInputDialog(null, "Enter the Search key ",
                                             "Search Key Input",
                                             JOptionPane.QUESTION_MESSAGE);
        int key = Integer.parseInt(input);
    for( int counter = 0; counter < array2.length; counter++)
          if (array2[counter] == key) {
            JOptionPane.showMessageDialog(null,
                                          "The search key was found in element " +
                                          array2[counter], "RESULT",
                                          JOptionPane.INFORMATION_MESSAGE);
    System.exit(0);
          else {
            JOptionPane.showMessageDialog(null,
                " No element was found for the search key ",
                "RESULT",
                JOptionPane.INFORMATION_MESSAGE);
            System.exit(0);
    }

    Get this. Microsoft says that this is a "Driver problem" and to check the latest installed driver. At first, I didn't think much of it because I havn't installed any drivers or hardware between the time it was working and the time it quit working....or so I thought.
    Apparently, one of the Microsoft automatic updates was a new processor driver for XP Pro. Since then, I cannot run any java programs without using JBuilder8. If I do, the computer reboots whenever the program reads the System.exit(*); line.
    Looks like Microsoft has found yet another way to sabotage java.
    Go figure.

  • System.exit(0)   error in program.

    Any help appreciated. Let me first put my code here:
    Converts money using CurrencyConverter, there's another class I haven't posted here!! (which calculates conversion)
    import java.util.* ;
    public class CurrencyConverterTester
      public static void main(String[] args)
        Scanner in = new Scanner(System.in) ;
        System.out.println("How many euros is one dollar?") ;
        String input = in.nextLine() ;
        double rate = Double.parseDouble(input) ;
        CurrencyConverter myconverter = new CurrencyConverter(rate);
        System.out.println("Dollar value (Q to quit)") ;
        input = in.nextLine() ;
        while (true) {
          if (input == "Q"){
            System.exit(0);
            break;}
          else {
          System.out.println(input + " dollar = " +  myconverter.convert(Double.parseDouble(input)) + " euros");
          input = in.nextLine();
          continue;}   
    }The issue is that the program won't terminate when I enter Q as my input?? I'm guessing it might have something to do my conversion from string to double in the 'else' statement, but not sure. Also, if you can suggest a more simpler method for the last 'while' statement, that would be helpful as well. Thanks. (noob to java)

    paulcw wrote:
    Curse Gosling for making &#43; syntactic sugar for string append, but not overloading any other operators.@Paul
    What did you expect from a duck ;-)
    Seriously, yep, maybe it would have been better for noobs if the syntax of Java Strings was consistent with other kinds of Object... or maybe it would have been better if == was compiler-magiced into stringA.equals(stringB)... and the left and right shift operators have promise, and of course that way lies MADNESS, as witnessed in C&#43;&#43; ;-)
    @OP... You are (IMHO) using the break, continue and especially System.exit() inappropriately... see my comments in your code...
        System.out.println("Dollar value (Q to quit)") ;
        input = in.nextLine() ;
        // while-true-loops are a "fairly usual" way of doing this kind of stuff,
        // but that doesn't make them "the preferred option". Typically you would
        // explore more "vanilla approaches" (which don't rely on the break and
        // continue statements)... leaping straight to the "tricky approach" means
        // you haven't (most often out of sheer laziness) thought it through... and
        // ALL good computer programs are thoroughly thought through (yep, try
        // saying that three times fast, especially after three beers).
        while (true) {
          // You don't compare Strings using ==
          if ( "Q".equalsIgnoreCase(input) ) {
            // Either of the following statements will do the job. The call to exit
            // will exit the JVM, therfore the break statement cannot be reached,
            // so it is superflous, so it's presence is just a bit confusing. Having
            // said that, "real programmers" don't use System.exe routinely, only in
            // the case of an emergency, such as handling a fatal-error, such as an
            // out-of-memory condition... an even then it's usually indicative of a
            // poor "system design", because it terminates the JVM which is running
            // this program without giving anything else in the program a chance to
            // clean-up after itself... like ask the user if they want to save there
            // work, or whatever.
            // I would use break (if anything) instead of System.exit
            // ... and if I wrote the Java tutorials, exit wouldn't be mentioned at
            // all until both "normal" flow control, and exception handling had both
            // been thoroughly covered.
            System.exit(0);
            break;
          } else {
            // I would break this line up, probably into three lines, simply becuase
            // it's syntatically "a long line".
            // Also the name "myconverter" doesn't tell what the class is/does.
            // IMHO, currencyConverter would be a better (more meaningful) name.
            // HERE'S HOW I WOULD WRITE IT
            // double dollars = Double.parseDouble(input);
            // double euros = currencyConverter.convert(dollars);
            // System.out.println(input + " dollar = " + euros + " euros");
            System.out.println(input + " dollar = " +  myconverter.convert(Double.parseDouble(input)) + " euros");
            input = in.nextLine();
            // This continue statement is superflous. continue says "go back to the
            // top of loop, reevaluate the loop-condition (true in this case) and
            // (if the condition is still true) "Play it again Sam".
            // ... which is exactly what will happen without this continue statement
            // and hence (IMHO) your code is easier to follow without it, simply
            // because another programmer may waste there time trying to figure out
            // WHY that continue statement is present.
            continue;
        }*ALSO:* The format of that code totally sucks. Braces all over the place; improper indentation. No wonder you're struggling to read your own code. Please read and abide the [The Java Code Conventions|http://java.sun.com/docs/codeconv/] (at least until you have the requisite experience to formulate credible and compelling arguments as to why your "style" is superior to the standard, and that's no small ask). Yes this is *important*... trust me on this (for now)... especially if you are going to ask for help on the forums... You're effectively wasting our time asking us to decipher your code because you are too lasy to format it correctly... and I for one find that "self entitled" attitude ugly, and offensive... Help us help you... you know?
    And BTW.... Here's how I would actually do it.... no funky while-true, break, or continue... just a plain-ole'-while-woop....
    package forums;
    import java.util.Scanner;
    public class KRC
      private static final Scanner SCANNER = new Scanner(System.in);
      public static void main(String[] args) {
        try {
          String input = null;
          while ( !"Q".equalsIgnoreCase(input=enterDollarAmount()) ) {
            System.out.println(input + " dollars is " +  Double.parseDouble(input) + " euros.");
            System.out.println();
        } catch (Exception e) {
          e.printStackTrace();
      private static String enterDollarAmount() {
        System.out.print("Please enter an amount in dollars : ");
        return SCANNER.nextLine();
    }Edited by: corlettk on 25/10/2009 10:21 ~~ Distant Monarching Forum Markup!

  • Is System.exit() a good call to use?

    I have a program that checks for updates in the db. If there are no updates in the database I want the program to stop. There are also many other conditions that would cause the program to stop. None of them are "Errors" so I wasn't using Exceptions to end the program The program runs from a command line or from chron job. Is it safe / OK to use System.exit() to do this?

    As you describe it, I'd say yes. System.exit() is the way to end your program.
    The danger of System.exit() is if a class you write will be reused in some other system. In that case, System.exit() could be entirely inappropriate in that context, thus preventing your class from being reusable.
    If you only call System.exit() in your main() method, you'll probably be OK.

  • Alternative for System.exit(0)

    Hi everyone........ I am using System.exit(0) to get out of the program but this will not close the connection objects etc..So suggest an alternative for that so that code can terminate in a proper way releasing all connection objects etc

    Well, the proper way for a Java program to end is for all it's (non-daemon) threads to terminate, System.exit(0) is inelegant.
    And if each thread cleans up the resources it allocated that automatically takes care of cleanup.
    But you can register a shutdown hook with Runtime each time you open an external resource. And/Or you can create a global List of shutdown processing items (e.g. Runnables) to invoke before shut down.

  • JVM 1.5 hang at system.exit(): how to debug ?

    Our Java application seems to sometimes hang indefinitely at System.exit().
    So far, we have observed that:
    - the hang does not happen when running JDK 1.4, but only with JDK 1.5 (we are trying to migrate to JDK 1.5.0_06)
    - it seems that if we comment out code that calls PrinterJob.print(), the hang does not happen
    - the hang can be observed on all our machines (different models), except one that is misteriously not impacted. OS is WinXP SP2.
    - when our software has sent a printer job to the printer and is running JDK 1.5, the problem can be reproduced after at most 4 or 5 tries, usually 1 or 2 runs being sufficient.
    - we have not been able to narrow the problem to a simple testcase (only reproduced using automated testcases on our application, which is 200.000+ LOC....)
    - when the JVM is stuck in System.exit, the process can be killed using the task explorer with the usual "program does not respond" and subsequent "send problem report" wizard after having killed it. (not to sure on exact wording in english...).
    We suspect a hard-to-hit regression or behavior change in JDK1.5 (there's no reason a java application could hang at System.exit(), right ?), but the above information is certainly far from being sufficient to open a bug report.
    So, any help to help us further identify the problem would be appreciated.
    More precisely, is there any way to try to understand the problem using a crash dump, or something like this ?
    Thanks

    I doubt that it hangs at System.exit(). Use jConsole (comes with your JDK) to connect to your application and inspect all running Threads which block at what exception stack trace.

Maybe you are looking for

  • How to insert data from file to table??

    I need to know that how can i insert data in multiple column through file. I can simply insert data in one column table but couldnt find out the way to put data in all column. My data store in a file ************************************************te

  • Cannot get 10.1.0.3 on linux Itanium to install on RHEL4

    I have been trying to get rdbms version 10.1.0.3 for Linux Itanium to install on a new HP rx6600 running RHEL4 and have not had much luck thus far...I have an open SR with metalink but still not much progress... Initially I had to download the oracle

  • Communication Channel  types for e Filing GB

    Hi radhika, For e-Filing Outgoing process the configuration Scenario is PAYE_EOY_GB. For e-Filing Incoming Process scenario is Employee_tax_code_update, In these cases,  GovernmentGateway is as sender for  -Filing Incoming Process and is as receiver

  • Featured list in app store doesn't appear. Gives an error messag. Using iPad on iOS5.

    As the title says. The App Store worked fine after the upgrade, but rcently it's been acting up. Any one who've had the same issue?

  • How to collect profiling information

    I try to use -Xrunhprof:cpu:old to collect some profiling information. However I got the following information: HPROF ERROR: thread local table NULL in method exit 08990B84 HPROF ERROR: thread local table NULL in method exit 08990B84 HPROF ERROR: thr