Using System.exit(0) in executeScript

When using System.exit(0) in executeScript within a process, it shuts down JBoss. This happens both
in LC ES2.5 and ADEP  10.0.1.20111108.1.309370
I would expect that System.exit(0) simply ends the script and returns control to the process. Am I
missing something here?
TIA,
Alex

gavas_java_nov26_exception wrote:
If i use System.exit(0) in the try block or catch block will finally block will be executed?
try
System.exit(0);
catch(Exception e){
System.exit(0);     
finally
System.out.println("finally!");
To tell you the truth, What does it matter? You shouldn't be doing that anyway, at least not in a well written program.
But, if you really want to find out, do as duffymo said, and try it. It'll only take a minute and save you the time (and embarressment) of asking here.

Similar Messages

  • How to "kill" AWT Event Queue thread without using System.exit()?

    When I run my program and the first GUI window is displayed a new thread is created - "AWT-Event Queue". When my program finishes, this thread stays alive and I think it causes some problems I have experienced lately.
    Is there any possibility to "kill" this thread without using System.exit() (I can't use it for some specific reasons)

    All threads are kept alive by the JVM session. When you use System.exit(int) you kill the current session, thus killing all threads. I'm not sure, though...
    What you could do, to make sure all threads die, is to make ever thread you start member of a thread group. When you want to exit you app, you kill all the threads in the thread group before exit.
    A small example:
    //Should be declared somewhere
    static ThreadGroup threadGroup = new ThreadGroup("My ThreadGroup");
    class MyClass extends Thread {
    super(threadGroup, "MyThread");
    Thread thread = new Thread(threadGroup, "MySecondThread");
    void exit() {
    //Deprecated, seek alternative
    threadGroup.stop();
    System.exit(0);
    }

  • If i use System.exit(0) in the catch block will finally block executed

    If i use System.exit(0) in the try block or catch block will finally block will be executed?
    try
      System.exit(0);
    catch(Exception e){
      System.exit(0);     
    finally
      System.out.println("finally!");
    }

    gavas_java_nov26_exception wrote:
    If i use System.exit(0) in the try block or catch block will finally block will be executed?
    try
    System.exit(0);
    catch(Exception e){
    System.exit(0);     
    finally
    System.out.println("finally!");
    To tell you the truth, What does it matter? You shouldn't be doing that anyway, at least not in a well written program.
    But, if you really want to find out, do as duffymo said, and try it. It'll only take a minute and save you the time (and embarressment) of asking here.

  • Problem using System.exit()

    Hai,
    I used System.exit(1) system call in my servlet code. When this part of code is executed the whole server goes down.. i need to know if there is another smooth way of exiting code instead of System.exit().
    Thanks

    is another smooth way of exiting code instead of System.exit().System.exit() is supposed to terminate the JVM....however, your server (especially I have seen Tomcat 4.x) can hang if you call System.exit()...because there may be some active threads still running in the JVM, and server is not able to terminate them...and gets stuck.
    What is your intent? If you want to cleanly shutdown the server, then don't call System.exit(), instead, the server listens on some port for commands, connect to that port and issue a quit/exit command. For example, in tomcat looking at server.xml you could look at this element <Server port="8005" shutdown="SHUTDOWN" debug="0">. Connect to port 8005 and issue "SHUTDOWN" command to gracefully terminate the Server.
    -BJ

  • How do I exit a java program based on condition can i use system.exit

    I have java program that is called by another program that I dont have control on. My program returns a bigdecimal... but if the ordernumber is empty in my program i dont wnat to do anything.. does system.exit work in that condition... i put it int he else if ordernumber is empty condition.. but i dont think that is the right approach..

    When software module is expected to bring some result, it should bring the result, positive or negative. I think you should check what your counterpart software expects as positive or negative result. And then implement your software this way. You can use System.exit, but this call is employed usually to indicate status with the software after it's completion and not to return any resulting value.
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#exit(int)

  • Closing a JFrame without using System.exit(0)

    Hello all,
    I'm writting an application at the moment that uses a JFrame as an "about box" invoked when a menu item from another JFrame is selected . The about box is set to undecorated, and I have set up an Thread to handle an animation of the credits that move up slowly. I have also added into it code to play a sound file while the credits are running.
    I wanted to have it so that the user can just click once anywhere on the Panel area of the about box, and that would close the about box window and stop the sound.
    I can get it to stop the sound on click no problem, what I'm having issues with is closing just the about box Frame. I've used System.exit(0) but this closes the original application, which I dont want it to do. I've been looking at online example code and I've found that dispose() might work... Problem is my JFrame for the about box is initiated in the main applications JFrame under an eventListener for the menuItem 'about'. The sound file is played inside the JPanel of the about box. And the listener to close it is located in the same place ( about box JPanel ).. does anyone know how to get this frame ( initiated in main applications JFrame ) and dispose of this frame through code located in the JPanel of the about box.
    I hope this is descriptive enough for you.
    Please let me know if you have any questions about my question.
    Many thanks,
    Mark.

    It seems you are asking how to find the parent frame of a Component that you know is within a frame?
    You can getParent() of the component. If it is a frame (instanceof) - dispose, else check for the getParent()...
    If you don't want to code it yourself use SwingUtilities.getWindowAncestor(Component) to get the Window in which the panel is.
    HTH
    Mike

  • Close using system.exit()

    could anyone tell me to write a new program which has a button labelled 'close'. when click on 'close', it should terminate the addition program.
    import javabook.*;
    class addition
         public static void main(String args[])
              int a, b,c;
              MainWindow mainWindow = new MainWindow(); // creates a frame,mainwindow is in javabook package
              InputBox inputBox = new InputBox(mainWindow); // creates an inputbox, is in javabook package
              OutputBox outputBox = new OutputBox(mainWindow);// creates an outputbox;
              outputBox.setVisible(true);
              a= inputBox.getInteger("Enter an integer: ");
              b=inputBox.getInteger("Enter and integer: ");
              c= a + b;
              outputBox.printLine("C = %d\n",c);
    }

    closeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
    });

  • 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.

  • 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 ...

  • 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.

  • 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

  • Read sharing violation after System.exit in oracle lite DLL

    I am using JRE 1.3 and successfully managed running some sql statements over jdbc.
    When the java class is finished (implicit exit) then no error appears.
    When I exit the code using System.exit(0) there is a windows dialog
    showing a read access error AFTER the java class finished.
    probably there is some cleanup the oracle DLL wants to do after the JVM exited?
    Please help mailto:[email protected]
    The sample code below can be used.
    * Title:
    * Description:
    * Copyright: Copyright (c) 2001
    * Company:
    * @author Ivan Motsch
    * @version 1.0
    import java.util.*;
    import java.io.*;
    import java.sql.*;
    public class TestOracleLite{
    public TestOracleLite(){
         public void start(){
              Statement stm=null;
              Connection conn=null;
              try{
                   Properties p=new Properties();
                   p.setProperty("user","system");
                   p.setProperty("password","manager");
                   p.setProperty("DataDirectory","..\\..\\..\\TEMP\\ora4\\db");
                   p.setProperty("Database","ORS");
                   p.setProperty("IsolationLevel","Read Committed");
                   p.setProperty("Autocommit","Off");
                   p.setProperty("CursorType","Forward Only");
                   String ps=getPropertiesAsString(p);
              Class.forName("oracle.lite.poljdbc.POLJDBCDriver");
                   conn=DriverManager.getConnection("jdbc:polite:whatever"+ps);
                   execSql(conn,
                        "drop table test1 cascade"
                   execSql(conn,
                        "create table test1(pk number(32),ncol number(32),scol varchar2(2000),dcol date,rcol long raw)"
                   conn.commit();
                   execSql(conn,
                        "insert into test1(pk,ncol,scol,dcol,rcol) values(?,?,?,?,?)",
                        new Object[]{new Integer(1),new Integer(1111),"Test Text",new java.sql.Date(System.currentTimeMillis()),new byte[]{0,1,2,3,4,5,6,7,8,9,10}}
                   conn.commit();
                   readSql(conn,"select * from test1");
              catch(Exception e){
              e.printStackTrace();
              finally{
                   if(conn!=null){
                        try{
                        conn.close();
                             conn=null;
                        catch(Exception e){e.printStackTrace();}
         private static String getPropertiesAsString(Properties p){
              StringBuffer buf=new StringBuffer();
         for(Iterator it=p.keySet().iterator();it.hasNext();){
              String key=(String)it.next();
                   String val=p.getProperty(key);
                   buf.append(";"+key+"="+val);
              return buf.toString();
         public boolean execSql(Connection conn,String s){
              return execSql(conn,s,(Collection)null);
         public boolean execSql(Connection conn,String s,Object[] binds){
              ArrayList list=new ArrayList();
              if(binds!=null) list.addAll(Arrays.asList(binds));
         return execSql(conn,s,list);
         public boolean execSql(Connection conn,String text,Collection binds){
              PreparedStatement stm=null;
              try{
                   stm=conn.prepareStatement(text);
                   if(binds!=null){
                        int i=1;
                        for(Iterator it=binds.iterator();it.hasNext();){
                             Object o=it.next();
                             if(o==null){
                                  stm.setNull(i,Types.VARCHAR);
                             else if(o instanceof byte[]){
                                  stm.setBytes(i,(byte[])o);
                             else{
                                  stm.setObject(i,o);
                             i++;
                   boolean b=stm.execute();
                   System.out.println("status: "+(b?"ok":"failed"));
                   return b;
              catch(SQLException e){
                   System.out.println("status: "+"error"+" "+e);
                   return false;
              finally{
                   if(stm!=null) try{stm.close();}catch(Exception e){}
         public boolean readSql(Connection conn,String text){
              PreparedStatement stm=null;
              try{
                   stm=conn.prepareStatement(text);
                   ResultSet rs=stm.executeQuery();
                   ResultSetMetaData meta=rs.getMetaData();
                   System.out.print("col: ");
                   for(int i=1,n=meta.getColumnCount();i<=n;i++){
                        System.out.print(""+meta.getColumnName(i)+", ");
                   System.out.println();
                   while(rs.next()){
                        System.out.print("row: ");
                   for(int i=1,n=meta.getColumnCount();i<=n;i++){
                             System.out.print(""+rs.getObject(i)+", ");
                        System.out.println();
                   return true;
              catch(SQLException e){
                   System.out.println("status: "+"error"+" "+e);
                   return false;
              finally{
                   if(stm!=null) try{stm.close();}catch(Exception e){}
         static public void main(String[] args) {
              TestOracleLite t=new TestOracleLite();
              t.start();
              t=null;
              System.exit(0);

    Hi
    After system copy you need to do post system copy activities...
    Please follow according to the installation Guide..
    for example: your sld connection of your new system will be pointing to your source system. So you need to go to VA where in you can find SLD Data Supplier and change the host name, port no relavent to this  i.e. your destination system...i.e.
    new system.. In the same way you can follow doing the post installation activites will solve your issue.
    Regards
    Hari

  • System.exit(0);???

    Hey all,
    Can anyone please tell me what this statement means and why the 0 is used. I know it is used to exit the program. But, I would like to know why it works.

    codingMonkey wrote:
    En-Wolf wrote:
    But, I would like to know why it works.Because that's what it's supposed to do. You can pass any int parameter to it, but as far as I know, by convention, zero means that no problem occured during execution, and calling exit(1), would mean that an error occured.Whatever int you pass in, that gets returned to the OS, providing it accepts int returns from programs exiting. By and large, you shouldn't need to use System.exit at all, and although it's tempting to use it to brute-force your app to stop, letting method calls return naturally all the way back to main is preferable. You can use System.exit() there to return whatever value you want to the OS

  • 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

  • Mac Error on System.exit(1);

    When I close my application, which is exported as runnable jar, using System.exit(1); I get an error.
    Mine is in Dutch, but translated it is:
    The Java-JAR-file 'file.jar' can't be started.
    Check Console for any error messages.
    Does anyone recognize this error?

    A non-zero return value usually indicates an error.
    Maybe Mac OS X takes this to the logical conclusion and shows the error when your app returns a non-zero return value.
    Try gimbal2s suggestion and tell us if it changes anything.

Maybe you are looking for