Force some statements when exiting program

Hello,
I have created a class,
I want that when the program exits,
it should have a code that will be done before the program exits.
The following is for initialization :
public class myClass {
Static {
... do something
// what should I put here for finalization ?
Thanks :)

addShutdownHook doesn't work for some conditions
(it seems to be work for simple pure java)
If I do :
JOptionPane.showMessageDialog ... - doesn't work
System.out.println ... - work !!!
Thanks :)A quote from one of the references found by the following search
Because shutdown hooks run as threads, you must use thread-safe programming techniques. Otherwise you risk having threads interfere with each other. Also, it's wise to design your application for simple and fast shutdown processing. For example, you might run into trouble if your application uses services during shutdown that are themselves in the processing of being shut down.
http://www.google.com/search?q=java%2bshutdown%2bhook

Similar Messages

  • Error using SHIFT statement when migrating program from R/3 4.7 to ECC6.0

    Hello Experts,
    The SHIFT statement is giving following error in ECC6.0 but the same is warning in R/3 4.7.
    "Floating point variable can not be used with SHIFT statement.".
    Statement is - SHIFT itab-f1 by 5 places where f1 is a floting point field.
    We passed the value in string variable and used in the SHIFT statement. It is removing the error but not giving the result same as in R/3 4.7.
    Please let me know how to solve this.
    Thanks and Regards,
    Rahul

    Hello,
    Thanks for the reply.
    We don't know why was this code written. We are just moving the object from R/3 4.7 to ECC 6.0 and fixing the errors.
    Could you please let me know "What it means to SHIFT a floating point variable by some spaces"? .
    This i am asking because SHIFT RIGHT generally means to shif the value to the right by some spaces i.e. inserting space at the starting.
    But in case of floating point it change the value itself. If you can tell me then i can find an alternative solution to get the same result.
    Thanks and Regards,
    Rahul

  • Dynpro application: how to perform some  code when user click window close

    Hello,
    I'm developing dynpro application. This application needs to perform some code when exiting.
    I can do that with MODULE xxxxx AT EXIT-COMMAND. But this code can't be performed when user of application click on button closing window (classic R/3 window, not pop-up).
    Does anybody know how to bind some code to clicking on button closing window?
    Best regards,
    Josef Motl

    As far as the prompt that you get when you close the last window is coming from the counter that SAP maintains regarding the number of open sessions(windows). When this counter reaches 1, I guess they have a check to issue a prompt. There was a discussion in this forum a long time back regarding how we can know that session id like SM04. There was no conclusion reached then. Theoritically, let us know you know this id for the session in which the user opened a particular page, then you can see if that session is deleted and then take the necessary action. There are some TH_* function modules that seem to be promising, but I was not able to conclusively achieve the control over a particular session.
    See if you can look at SM04 and get an idea. Please do let us know if you find the solution.
    Srinivas

  • My Mac is running slowly and having some glitches in opening programs.  How can I clean upspace?

    My Mac is running slowly and having some gliches when opening programs.  How can I clean up the disk to make it more efficient?

    learn how to use Recovery Mode
    Don't do anything until you can restore and have repaired the disk drive.
    Post should get moved to either ML (10.8,.4) or iMac forum
    Swap out the hdd for an SSD : )
    Don't do anything to clean it up unless you don't know how to first remove browser history from within the programs; low on disk space (I consider more than even the 15% minimum, more like 3--40%)
    And do you have page outs? more than enough RAM? what actually leads you to ask? Programs aren't opening properly?
    Sometimes it is easier to take the long road: just reinstall and restore.
    Recovery Mode
    http://support.apple.com/kb/HT4718
    TimeMachine 101
    https://support.apple.com/kb/HT1427
    http://www.apple.com/support/timemachine
    Mac OS X & Mountain Lion Community
    https://discussions.apple.com/community/mac_os
    General purpose Mac troubleshooting guide:
    Mac OS X: Starting up in Safe Mode - http://docs.info.apple.com/article.html?artnum=107393
    What is Safe Boot, Safe Mode? (Mac OS X) - http://support.apple.com/kb/HT1564
    Isolating issues in Mac OS X
    Creating a temporary user to isolate user-specific problems:
    Isolating an issue by using another user account
    Identifying resource hogs and other tips:
    Using Activity Monitor to read System Memory and determine how much RAM is being used
    Starting the computer in "safe mode":
    Mac OS X: What is Safe Boot, Safe Mode?
    To identify potential hardware problems:
    Apple Hardware Test
    General Mac maintenance:
    Tips to keep your Mac in top form  

  • 1. Force closes often when  I get on this support page. 2)  guy who installed apps used his own itunes acct. Now i cant update. I tried deleting and reinstalling but i end up paying 2xfor the same apps. 3) there are some apps which i know I installed but

    1) iPad force closes often when I get to support page
    2) guy who installed apps on iPad used his own iTunes account. Is therea way for me to update using my own account? I've tried deleting and reinstalling but I end up paying 2x for the same apps :(
    3) I also know I installed some apps on my own account but when I try to update them, the installer guy,s apple I'd comes out. Is there A way to change that?
    Thanks for helping out a newbie non- techie :))

    1) iPad force closes often when I get to support page
    Can't help you with that.
    2) guy who installed apps on iPad used his own iTunes account. Is therea way for me to update using my own account? I've tried deleting and reinstalling but I end up paying 2x for the same apps
    Who does this iPad belong to? If someone else used their account then they paid for the apps. You will need to buy and pay for apps using your own account which means that you will no longer have access to the apps installed by the other person.
    3) I also know I installed some apps on my own account but when I try to update them, the installer guy,s apple I'd comes out. Is there A way to change that?
    If this iPad belongs to you I suggest you reset the iPad to factory defauts and just use it with the apps that you've paid for. You will be able to re-download the apps from the iTunes app store after the reset.
    Follow this guide to reset the iPad to factory settings.
    http://ipad.about.com/od/iPad_Guide/ss/How-To-Restore-An-iPad-To-Factory-Default .htm

  • How do I Initialize a button to be enabled when the program start and if pressed then disable and gray it until a certain action is taken then comeback to the enabled state?

    Hi!!!
    I'm doing a program with the following buttons: Run, Abort, Repeat and Exit. When the program starts from the first time only Run and Exit button will be enabled and not disabled so the user doesn't press the Abort and Repeat button. The user has to select from a menu bar the test he wants to make then if he presses the Run button a pop up window will come up asking for the serial number and his name, and will comeback to the main program with the entered information. The user now has to press the Run button again to start the test, when the test starts the Abort button now will be enable
    d and not disabled, when the test ends the Repeat button will be enabled and disabled. If the user selects new test from the menu bar the whole process will come again. I'm having problems with the menu bar because it has a time-out and when that occurs the program gets crazy. Also I'm not sure about what mechanical action I have to use for the Run. Do I need to count the times the Run button is press so the 2nd time is pressed it will be disabled. Do I need to use a sequential and where I initialize the buttons so the first time they are like I want (Inside or OUtside the while loop that ends with the Exit button) Any help wil be appreciated.

    I'm not sure about the menu bar because i've never used them..i tend to go for listboxes instead.
    As for the buttons, if you want to wire the button to a local variable then the button must be a switch, otherwise a latch is ok. But remember you will probably need to reset the button at the end of a run (ie. wire a constant through the while loop to the local variable for the switch). To initialize the buttons at the start, wire constants to their locals outside the main execution while loop.
    Put the disabling/enabling functions in the parts of the program the button has activated. For example, you say the 2nd time the Run button is pressed you run the 'test', enable the Abort button and want to disable the Run button - put these property nodes into th
    e 'test' sequence/loop.
    Sequences are useful to control when you want buttons to be modified. I use them if i cant sequence the order of execution any other way. But try and avoid using multiple frames as it can get confusing if you start hiding code.
    If you are still having problems, post an example of your program in no higher than LV 6.0.2 and i will try and adapt it for you.
    Kim

  • Program Crash When Exiting Editor

    I am running Photoshop Elements 8.0 on a Gateway PC with Windows 7 Premium Home version. I installed both Photoshop and Premiere Elements without errors. Whenever I used the editor in photoshop I get an error when exiting ther program. I get a message saying the program stopped unexpectedly and get the following:
    PhotoshopElementsEditor.exe - No Disk
    There is no disk in the disk drive. Please insert a disk into \Device\Harddsk1\DR1
    I have to click cancel several times until the message goes away.
    Any ideas?

  • I reinstalled acrobat 8 on my computer but when I try to print to a pdf it states that the program isn't activated.  I tried to install and reinstall it but it still doesn't work.

    I reinstalled acrobat 8 on my computer but when I try to print to a pdf it states that the program isn't activated.  I tried to install and reinstall it but it still doesn't work.  It shows that it is activated.  I tried to deactivate and reactivate but that doesn't help either.  Everything else seems to work.

    Hi tspcat,
    What operating system are you using, and what version? You may be running into a compatibility issue between your older version of Acrobat and the OS that you're running.
    Please let us know a bit more about your setup, so we can get to the bottom of this printing issue.
    Thanks,
    Sara

  • I could not exit Safari so had to Force Quit but when I open it goes right back to the Yahoo home page that would not close. There was a little light under the Safari icon which told me that Safari was still running. Any ideas??

    I could not get out of my Yahoo home page in Safari on my Imac. I had to force quit but when i opened back up the little light under the Safari icon was still on and when i tapped icon I was right back to the Yahoo page which would not close. Any ideas???

    Quit Safari (by force if necessary.) Relaunch it by holding down the shift key and clicking its icon in the Dock. That will stop the page from reloading automatically.

  • How to do some cleanup when closing JFrame

    Hi all,
    1st: Is it possible to call a method (or something) when the user clicks the close button on a JFrame so that some cleanup can happen before exiting? I have a dropdown menu that has an exit button which calls a method that performs a whole lot of neccesary cleanup operations. The problem is that Im not sure how to call that cleanup method if the user clicks the 'x' instead of exititing with the menu. (I know Java has automatic garbage collection but there are additional things i need to do when the program exits)
    2nd: Once ive done all the necessary cleanup is it correct to simply call Sytem.exit(0); ? Is that a safeway of closing the program?
    3rd: How do you display multiple lines of text on a JButton? I have a button wich has a small amount of horizontal space and so I need to display the text on two lines but I cant figure out how to make the text rollover. Ive tried using '\n' which doesnt work., and there is no multiline or rollover property that I am aware of.
    Much appreciated. R
    ps. Is there a page here where i can read more on assigning dukes and rewarding them? Im feeling stingy not knowing how to assign them to helpfull people.

    You might also want to have a look at shutdown hooks. You can use them to be sure that certain cleanup will happen before exiting even if exiting was forced because of your application crashing or the user killing it through the task manager or the unix "kill" command.
    http://java.sun.com/developer/TechTips/2000/tt0711.html#tip1
    2) calling Sytem.exit(0) will be enough
    3) There are a couple of ways: you can use HTML in the label or do something a bit more fancy:
    http://javaalmanac.com/egs/javax.swing/button_MultiLine.html
    http://www.javaworld.com/javaworld/javaqa/2000-03/01-qa-button.html
    4) The Duke Dollars FAQ is at http://forum.java.sun.com/rewardFaq.jsp

  • Submit statement in ABAP program

    Hi All,
          I am using two submit statements in my program for two different reports. When i run the program i get the output screens of the two reports at the ouptut. Is there any way i can hide the user seeing the output screens of the two programs and display only the output screen of my program. If you have any clues please post it.
    Thanks & Regards,
    Rahul Rathi

    You can call executable programs from other ABAP programs using the following statement:
    SUBMIT <rep>|(<field>) [AND RETURN] [<options>].
    You can either specify the name of the program you want to call statically by entering the program name in the code of the calling program, or dynamically by specifying the name of a field (in parentheses) containing the name of the program. If the system cannot find the specified executable program when trying to execute the SUBMIT statement, a runtime error occurs.
    If you omit the AND RETURN addition, all data and list levels of the calling program (the entire internal session) are deleted. After the called executable program has finished, control returns to the level from which you started the calling program.
    If you use AND RETURN, the system stores the data of the calling executable program and returns to the calling after processing the called program. The system resumes executing the calling program at the statement following the call.
    The SUBMIT statement has a set of additions <options> for passing data to the called program and specifying various other processing options. Some of them are described in the following sections:
    Have a look at below link. It will help you.
    http://www.sapdevelopment.co.uk/reporting/rep_submit.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9dd035c111d1829f0000e829fbfe/content.htm
    Best Regards,
    Vibha
    *Please mark all the helpful answers

  • How to use subroutine in user-exit program

    Hi Experts,
        I have a requirement in user-exit where i have to use some lines of code in several times. So i want to use Perform and perform inside the exit (i.e. Include ZXXX). But it is not recognizing the form part of the ubroutime and gives error.
                 Please let me know how to use the Perform and form statement in the exit or is there any way to  write repeated code once but used no of times in exit program.
    Thanks
    Ajit

    I'm sorry, I was overly harsh there. Please accept my apologies.  But I do despair sometime!
    Consider the structure of a function group and it should be clear - you need to remember that INCLUDES are just repositories of code. If you take the contents out of the include and put them into the main program, then this is what you get:
    function-pool xrsr.        
    * Global data definition.
    function exit_saplrrs0_001.
    * the source code within the zxrsru01 include.
    endfunction.
    Now, what you're trying to do, is create a form in your include. You can't do that, because you end up with:
    function-pool xrsr.        
    * Global data definition.
    function exit_saplrrs0_001.
      perform xyz.
      form xyz.
      endform.
    endfunction.
    And you can't have a FORM defined inside a function module definition. The solution is to put it outside the function module. If you follow the process suggested above, you end up with
    function-pool xrsr.        
    * Global data definition.
    function exit_saplrrs0_001.
      perform xyz.
    endfunction.
    form xyz. " This will be in LXRSRF01
    endform.
    Do you see how it works now?

  • Keep receiving a pop up from McAfee that states "Potentially Unwanted Program Blocked"

    I'm very new to owning and operating my own home computer.   Internet just recently installed.   While trying to find a safe "Minecraft" game for my grandson to pay, I now receive the message from McAfee that states "Portentially Unwanted Program Blocked".     What to do    What to do

    Hello,
    Thank you for posting in the HP Support forum.
    Most probably when you wanted to download the game, it was bundled with malicious/unwanted software, thus stopped by McAfee.
    Here you can find some information about the types of the viruses/malware/Internet attacks:
    http://kb.eset.com/esetkb/index?page=content&id=SOLN186&actp=search&viewlocale=en_US&searchid=141592...
    If you continue getting messages from McAfee that virus or unwanted program is present or deleted, double check with different utilities because McAfee may be picking-up only part of the story (aka undetected malware)
    Read this article and perform STEP 2 , 3 and 4  only   http://malwaretips.com/threads/how-to-remove-trojans-spyware-rogues-and-other-malware.6941/
    As for safe Minecraft game, there are literally hundreds of variants. Search for them using Google/Bing or ask in a gaming forum for recommendation. Use one from reputable sources.
    Best wishes,
    IT_WinSec
    Hewlett-Packard employee | HP Enterprise Services
    Although I work for HP, I express my personal opinion.
    Visit www.hp.com/makeitmatter
    --Say "Thanks" by clicking the Kudos Thumb Up in the post that you find useful.
    --Please mark the post that solves your problem as "Accepted Solution"

  • How to find out when a program was last executed

    Hello,
    I have a assignment to find out when some programs where last executed in the past 2 years or so. My question to the profs here is as follows? What are the possibilities in ABAP to out when a Program (report) was last executed? Is there a function Modul that can give you when a program was last executed? OR is there a table to show you when a program was last executed?
    Thank you for your help.
    Sabina

    Hi,
    use the t.code STAT,STAD.
    Check in this link for a sample code..
    https://forums.sdn.sap.com/click.jspa?searchID=421554&messageID=1488089.
    From Table TRDIR also you get the information about Last change.
    TRDIR-UDAT ---> Changed On
    TRDIR-UNAM ---> User Name
    Regards
    Kiran Sure

  • InputVerify ... ugly shouldYieldFocus when exit dialog or windows

    yes, maybe I should just skip InputVerify, but I figure I maybe able to learn somethere here.
    I am verifying make sure the jtextfield only has number and it's a required field, everything is okay here. but when I tried to close my dialog it pops up the InputVerify message.
    My cancel button uses
    buttonCancel.setVerifyInputWhenFocusTarget( false);  of course the dialog didn't have that method
    so I tried to search for some idea, but so far I think I had to use override shouldYeildFocus() method, but can I make the jcomponent to see it's a dialog not jtextfield??
    This is kinda close.
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=739038
    also I tried to add a method QuitListener
    protected class QuitListener implements ActionListener, WindowListener {is there a way to disable InputVerifer?
    Message was edited by:
    ekin_00
    add code around setVerifyInputWhenFocusTarget
    Message was edited by:
    ekin_00

A: InputVerify ... ugly shouldYieldFocus when exit dialog or windows

Works fine in the [url http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html#inputVerification]Input Verification Demo.
I changed the code to display the panel in a dialog instead of the JFrame.
//        frame.setContentPane(newContentPane);
        //Display the window.
        frame.pack();
        frame.setVisible(true);
        JDialog dialog = new JDialog();
        dialog.setContentPane(newContentPane);
        dialog.pack();
        dialog.setVisible(true);And if you add code to display an option pane in the verify method you need to do it like this to get around a bug:
        public boolean verify(JComponent input) {
             boolean value = checkField(input, false);
             if (value == false)
            input.setInputVerifier(null);
            JOptionPane.showMessageDialog(null, //no owner frame
                                          "something is wrong", //text to display
                                          "Invalid Value", //title
                                          JOptionPane.WARNING_MESSAGE);
            input.setInputVerifier(this);
               return value;
//            return checkField(input, false);
        }If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

Works fine in the [url http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html#inputVerification]Input Verification Demo.
I changed the code to display the panel in a dialog instead of the JFrame.
//        frame.setContentPane(newContentPane);
        //Display the window.
        frame.pack();
        frame.setVisible(true);
        JDialog dialog = new JDialog();
        dialog.setContentPane(newContentPane);
        dialog.pack();
        dialog.setVisible(true);And if you add code to display an option pane in the verify method you need to do it like this to get around a bug:
        public boolean verify(JComponent input) {
             boolean value = checkField(input, false);
             if (value == false)
            input.setInputVerifier(null);
            JOptionPane.showMessageDialog(null, //no owner frame
                                          "something is wrong", //text to display
                                          "Invalid Value", //title
                                          JOptionPane.WARNING_MESSAGE);
            input.setInputVerifier(this);
               return value;
//            return checkField(input, false);
        }If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

Maybe you are looking for