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.

Similar Messages

  • Alternative for field exit on select-option

    Good afternoon,
    I know that field exit doesn't work for select-option (SAP Note 29377, point 11) but i want to know if it exists an alternative (I use SAP 4.6, and an update to ECC6 is expected next month).
    The field exit would be the best option because we must add exit in many transaction (approximately 100) in little time.
    Thanks for your answers,
    Best regards,
    Anne.

    Hi
    A) Are there any way for debbuging field exit?
    The trick to debug the field-exit is to download the data to a file on application server;
    B) How run the field exits on field no editable?
    It can't do it, because a field-exit is triggered as soon as a value of the field is changed.
    D) Is used the field exit on version >= 4.6C
    SAP doesn't support the field-exit from realese 4.7: the field-exit still works on the realese 4.7 and, I suppose, 5 and 6.00: but it doesn't work for enjoy transactions.
    Anyway I believe it's better to replace the field-exit with a new solution from realese 4.7
    Max

  • Alternatives to Field Exit for executing a transaction?

    Hello,
    i'm looking for a way to add code to an existing dynpro, so that a double-click on a field executes a different transaction. As far as i know this is not allowed in a field exist. If there's also no BADI-method defined, what else can be used? Is there any other way than changing the current code of the application itself?
    TIA!

    Hi,
    The alternative for field exits after R/3 4.6C has been the enhancement Points...
    Check in debugging if there exists an implicit enhancement point in the PAI of the screen,
    If so you can add your code to call a new transaction...
    Regards
    Shiva

  • Preventing System.exit()

    I've written a class loader that executes .jar files across a network from a central application. Works great - except when one of those jar files calls a System.exit().
    Since the purpose of this application is to have several applications "executing" across a network, having one of them call System.exit() kills all of them. Are there any methods of scanning the class files as they are being loaded and having code replaced? For example, searching for System.exit(someInt) or even JFrame.EXIT_ON_CLOSE and then replacing this bytecode with some more acceptable bytecode that instructs the parent program the child wishes to terminate?
    Rewriting all of the programs to be loaded so that they don't call System.exit() or its variations isn't an option here, so I'm open to any suggestions.

    BTW: Overriding system libraries is against
    standards, but does work.
    http://java.sun.com/j2se/1.4.2/docs/guide/standards/
    In java.lang.Runtime
    public void exit(int status) {
    throw new Error("Exit called with
    led with status="+status);
    }Create a jar and copy it to <java_home>/lib/endorsed
    The run the following
    public class Main {
    public static void main(String[] args) {
    System.exit(1);
    }And you will get the follow when run with this
    "modified" JRE
    "C:\Program Files\Java\jre1.6.0\bin"\java -cp .Main
    Exception in thread "main" java.lang.Error: Exit
    called with status=1
    at java.lang.Runtime.exit(Runtime.java:86)
    at java.lang.System.exit(Unknown Source)
    at Main.main(Main.java:11)
    Yes, but then it works only on your machine.

  • System Exit Overriding Busy Loop

    Hi,
    Why would the following code not result in a clean JVM termination when SIGINT is sent? The JVM appears to capture the SIGINT correctly (it hits the shutdown hook), but the System.exit(-1) call cannot seem to override the busy loop and terminate the spawned thread. Is this expected behavior for the VM?
    public class TestSigInt {
         public TestSigInt()
              new Thread()
                   public void run()
                        while(true)
              }.start();
              Runtime.getRuntime().addShutdownHook(new Thread()
                   public void run()
                        System.exit(-1);
         public static void main(String[] args)
              TestSigInt tsi = new TestSigInt();
    }Thanks,
    hhung

    Is this expected behavior for the VM?Yes. See javadoc for System.exit(), that leads to to Runtime.exit():
    If this method is invoked after the virtual machine has begun its shutdown sequence then if shutdown hooks are being run this method will block indefinitely
    So the method blocks (and presumably does nothing, but I admit I'm making up that last bit) if called as part of a shutdown hook.
    the System.exit(-1) call cannot seem to override the busy loop and terminate the spawned threadRegardless of the fact that it's called from a shutdown hook, which previous messages (and the javadoc quoted) already question, there's nothing in the API javadoc that suggests that threads are gracefully "terminated".
    This situation is not different from regular situations when you want to nicely end a thread in an otherwise running Java application: the API does not provide any built-in API (except Thread.stop() and destroy() which are deprecated and which use is strongly discouraged) to stop a running thread.
    See Thread.interrupt() which somehow "kindly" requests interruption of a running thread, but this requires cooperation of the target thread (whose code shoud regularly poll Thread.getCurrentThread().isInterrupted() and terminate accrodingly).
    The usual recommendation to make this more explicit in the code, is that the thread's code regularly checks a business-logic specific boolean, such as:
    class StoppableTask implements Runnable {
        private boolean shouldContinue = true;
        public void run() {
            while (shouldContinue) {
                // do stuff
        public void requestStop() {
            shouldContinue = false;
    public void class StopperThread {
        StoppableTask target;
        public void doOtherStuff() {
            target.requestStop();
    }This requires cooperation form the target thread's code as well, so this is not conceptually different from the interrupt() scheme, it just has different scope (it won't unblock IOs for example).
    Note that I deliberately used Runnable as opposed to Thread, first because it is a recommend practice (but you may know that already and your example was intentionally shorter to get to the point), second to highlight that the specific-solution does not use any built-in java.lang.Thread method.
    Edited by: jduprez on Dec 8, 2009 11:28 AM

  • Alternative to System.getProperty("microedition.hostname")

    Hey is there any other alternative for 'System.getProperty("microedition.hostname")' to get the ip address of the device running the j2me midlet ??
    When you run the midlet on the emulator, System.getProperty("microedition.hostname") returns the PC's Name, but on a Nokia series 40(3rd E) device, it returns null.
    So is there an alternative to this to select the device's ip address ?

    First this is a pretty specific question which applies to a specific device rather than to reflection/reference. You might want to look for a forum that addresses the specific device.
    Second, you can print the system properties normally. Whether you can do that on the device depends on the device. If you succeed you might find an alternative.
    Third normally one uses the java.net.IpAddress to get a device IP. Does that not work for that device?

  • Intercepting System.exit() and System.out.println() calls

    hi there,
    I have often problems when working with code that uses System.exit() and System.out.println() extensively, because it becomes difficult to debug.
    Basically I do have wrappers for System.exit() (my own static exit function) and for System.out.println() (log4j).
    Still not all programmers are using these methods; Probably the only way to enforce this is some kind of code warrior, but I was hoping to be able to intercept the two System.XXX calls (and throw an appropriate Exception). is this possible ??

    Why not simply make your own security manager andhandle checkExit() and checkWrite?
    Does anyone have a simple example of this? Please?System.exit() can be intercepted using a security manager, but not System.out.xxx.
    Here is a short example:
    //set your security manager
    static{
         SecurityManager s = new OwnSecurityManager();
         System.setSecurityManager(s);
    //redirect the out stream
    try{
         PrintStream ps = new PrintStream(new FileOutputStream("output.txt"));
         System.setOut(ps);
    }catch(IOException ioe){
         ioe.printStackTrace();
    //some tests
    System.out.println("Test");
    System.exit(2);
    //your security manager
    class OwnSecurityManager extends SecurityManager{
         public void checkExit(int code){
           if(code > 0){
             super.checkExit(code);
             throw new SecurityException("Not allowed here->" + code);
         public void checkRead(FileDescriptor fd){
         public void checkRead(String file){
         public void checkRead(String file, Object context){
         public void checkPermission(Permission perm){
           if(perm.getName().equals("exitVM")){
             System.out.println("exitVM");
    }

  • System.exit(int) - Just For Fun

    import java.applet.*;
    public class BrowserKill extends Applet {
      public void init() {
        System.exit( 0 );
    }Terminate JVM while the browser is trying to contact JVM.
    Wow ... I've tried this code in IE 6.0 ... It crashed my browser ...
    What do you think ?
    You can try this code in JSP/Servlet ...
    I'm sure that the server will be crashed. (Because of terminating JVM)

    Wow ... I've tried this code in IE 6.0 ... It crashed my browser ...
    What do you think ?Serves you right for using such a rubbish browser. The security manager should have trapped the call and thrown a SecurityException, killing the applet but not the VM.

  • How to implement Help System for an exit Web application

    I want to know detail steps to use OHW create a Help System for an exit ADF web application.
    I read a lot doc about Oracle Help.
    I down load the demo bundle and test it. It seems working. But it need to start separately. Also I do not know how to use it to build a help system for an exit ADF web application.
    Any body can help me to learn HOW with jdeveloper step by step.
    Thanks.

    Frank,
    Thanks for your reply.
    I checked the site that you mentioned.
    I try the sample “demo with bundle. The sample worked.
    But it needed to start separately with the application.
    I do not know how to build a help system with the existed web application developed with Jdeveloper (It has two projects: model and user-view-control. It is deployed on Oracle Application server).
    Could you help me step by step to build the help system?

  • 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);
    }

  • Any other alternative for console??

    Just wanted to ask if there is any other alternative instead of using console in this program.....
    Console c = System.console();
            if (c == null) {
                System.err.println("No console.");
                System.exit(1);
            String enter = c.readLine("Enter your username: ");
            char [] oldPassword = c.readPassword("Enter your old password: ");
    ......................can i use any other function that is available and has almost the same as console...?

    Why? What is wrong with upgrading to 1.6 (which the code is written for and which you were told here: http://forum.java.sun.com/thread.jspa?threadID=5226598)? But, the "Console" stuff added to Java 1.6 come form an earlier third party library (if I remember right). I don't remember which one, but you should be able to Google Java Console API and find it rather it easily.

  • System.exit(int) and javac def-use calculation

    I'm wondering if anyone can tell me why javac (J2SE v1.4.2) seems to ignore "System.exit(int)" (alternately, "Runtime.getRuntime().exit(int)") for the pursposes of determining possible variable access before an initialization.
    For example, consider the following code:
    /*01*/  public class C {
    /*02*/    public void foo() throws Exception {
    /*03*/      C obj;
    /*04*/      while (true) {
    /*05*/        try { obj = new C(); }
    /*06*/        catch (Exception fault) { System.exit(1); }
    /*07*/        obj.foo();
    /*08*/      }
    /*09*/    }
    /*10*/  }Compile this (ignoring the absurdity of what "foo()" actually does), and you will get a variable obj might not have been initialized error. This despite the fact that a call to "System.exit(int)" never returns normally, by definition. To illustrate why this error doesn't make sense, substitute the "System.exit(1)" of line #6 with any of "break", "return", or "throw new Exception()". The use calculation for variable 'obj' is correct in these three alternate situations, but not for the first, even though the situation is analagous.
    Obviously, there is an easy work-around to this (viz., change line #3 to "C obj = null;"), though it seems unnecessary. Any ideas?

    System.exit() doesn't have the same "special" meaning
    to the compiler as "break", "return", or "throw" do.
    As far as the compiler sees, you are simply calling a
    method in your exception handler; it doesn't know
    that there will be no return from that method. Sure,
    the compiler could special-case System.exit(), but
    then you'd still see this same problem if you came up
    with your own wrapper method that calls
    System.exit().. the compiler in general doesn't (and
    shouldn't) assume that a method call will terminate
    the app.I understand that "System.exit(int)" is merely a method from the perspective of the compiler, but it is a rather special method (actually the "Runtime" version, for which the "System" version is merely a wrapper) with respect to correct program execution, calculated during the various traces that are done during compilation. And wrapping "System.exit(int)" with another method wouldn't make any difference to the calculation if it was considered, from the perspective of compilation, an uncaught (implicitly declared non-Runtime) exception. Besides, there must be some execution sequence within "Runtime.exit(int)" that serves, essentially, the same function as an "exit" keyword.
    What's wrong with supplying a default value when you
    declare the variable?Absolutely nothing, except that it isn't necessary. I typically do so anyway, and only came across this "feature" of javac during a lapse of my coding standards.

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

  • No Service for System SAPECC(Sender Port), Client800(R/3 system client 800)

    Hi friends,
    I am new to XI/PI I am working with IDOC to Flat file scenario I am facing the folllowing error.
    No Service for System SAPECC(Sender Port), Client800(R/3 system client 800) in integration Directory.
    can any one tell what was the reason for this error.
    Thanks in Advance,
    Ravi Yasoda.

    Hi Ravi,
    Have you imported the Business System in Integration Directory?
    Check whether  you see the logical system name in adapter specific identifiers or not...
    Also check from integration directory that cache notification was done and also check SXI_CACHE in the abap stack.
    See this thread...
    No service for system SAP***, client 001 in Integration Directory
    Please go through below content from sap note  for your issue...
    Error message: No service for system SAPABC client 123 in the integration directory
    Solution:
    You send IDocs from system ABC to XI. In the control record of the IDoc,the SNDPOR field contains the value "SAPABC". The client of the sending system is determined by the MANDT field of the control record. The system ID and client are then used to determine a service without party of the
    type (business-system/business-service):
    Business system
    -> Activities in the System Landscape Directory (SLD)(Create technical
    system):
    Create a technical system for system ABC in the SLD, and create the client for this. Do not forget to assign an "ALE logical system" (for example, "ABCCLNT123") to this technical system.
    SLD (Business system):
    You can now explicitly assign a business system to this client. For more details, refer to the SLD documentation.
    Activities in system ABC (self-registration in the SLD):
    Alternatively, you can register the system in the SLD in system ABC with Transaction RZ70. You will find detailed information about the SLD registration of systems on the SAP Service Marketplace for the
    "Exchange Infrastructure" in the document "Exchange_Installation_Guide.pdf".
    In system ABC, you can check your configuration with Transaction SLDCHECK.
    Activities in Integration Directory (import business system from SLD):
    You will find the business systems under Services Without Party in the Integration Services. In the Service menu, you will find the system identifiers, the client, and the corresponding ALE logical
    system under "Objects"->"Adapter-specific identifiers". Use the Import/Update button to copy the data from the SLD, to create business systems, or to update their identifiers.
    Business service
    -> Activities in the Integration Builder directory:
    You want to create a service without party that is not part of your system infrastructure and is therefore not maintained in the SLD. In the Integration Builder directory, you will find the "Business-Services" under Services Without Party. In the Service menu, you will find the system identifiers, the client, and the corresponding ALE logical system under "Objects"->"Adapter-specific
    identifiers".
    Activate the change list in Integration Directory.
    In system ABC, you can restart the incorrect entry from Transaction SM58 .
    Regds,
    Pinangshuk.

  • 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

Maybe you are looking for

  • Links in Reports

    Hi, is there any way to open a new browser window when we click on linked field in a report? The default behaviour is to open the linked page on the same window. Thanks.

  • HP LaserJet 4250 will not print

    I have an HP Laserjet 4250 that will not print from any of the 15 stations it is set up to.  I send print jobs to it, and I have to power the cycle the printer in order for it to print.  I have deleted and re-added the printer to the workstations, an

  • Firewire issues with DV camera

    When connecting a Samsung VP-D305i mini DV camera to the firewire port (4pin to 6pin cable) Mac OS fails to recognise it. I know this is an issue that has been covered in this forum a few times, but none of the answers seem to work for me. Furthermor

  • Soap Header in Xcelsius: How to pass Credentials

    Using Xcelcius 2008 (Excelcius Engage)  We are making a dashboard application which uses the Web service connection to call SOAP based web services. Is there a way to Authenticate the Web Services passing User ID pwd from within one of the excel cell

  • Key not working properly

    I bought E-71 about one month back. I upgraded its software to 110.07.127. After this upgrade process, the keys are not working properly. For example, the key titled '?' is not printing '?' while another key titled '.' is printing '?'. This problem i