How to put main process to sleep??

Hi experts
I have another problem in my ajav application , When I press execute button, it creates a process which run a bat file. the bat file actuallty run something and produce the output file. then main process read that output file and show the content in the result panel . Now in order to finish the process, I put the main process to sleep, other wise it cant find the file or it shows incomplete file/empty file. I use Thread.sleep(2000). But this is not appropriate , sometimes the files might be big or the bat file might need much time to finish which is common senario , In that case,I wont get appropriate output. My question is how can I put the main process to sleep until the the other process finish creating the file.
Any clue is helpful. Pls help. I am stucking at this point.
public class ButtonHandler implements ActionListener {
     GUIPanel guiPanel;
     ButtonHandler(GUIPanel gp){
          guiPanel=gp;
      public void actionPerformed (ActionEvent e){                    
          JButton button = (JButton)e.getSource();
          if(button == guiPanel.excButton){
               runBatFile(); // run the batch file
               try { // put main process to sleep
                    Thread.sleep(4000);
               } catch (InterruptedException ex) {
                    System.out.println("Too much Caffine! Cant Sleep..");
                    System.out.println("Error:" +ex);
               }//end of catch
               parseResult();     //show the output               
          if(button == guiPanel.closeButton){
               System.exit(0);
      }//end of fucntion
     public void runBatFile(){
          Process p=null;
          try {
                //p = Runtime.getRuntime().exec("test.bat");                 
          } catch (IOException e1) {
                   System.err.println(e1);     
          }//end of catch      
     }//end of function
     public void parseResult(){
          try {
               BufferedReader in=new BufferedReader(new FileReader("test.txt"));
               String s1;
               JTextArea jta=new JTextArea();     
               jta.setFont(new Font("Serif", Font.BOLD, 14));
                 jta.setEditable(false);
               JScrollPane jsp = new JScrollPane( jta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                                           JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS );
               jta.append(" ");     
               int lineCount=0;
                  while((s1=in.readLine())!=null){
                    System.out.println(s1);
                    lineCount++;
                    jta.append(s1);
                    jta.append("\n");
               }//end of while
               in.close();
               jta.append("\n\nI am done with it:"+ lineCount+"\n");
               resultPanel.removeAll();                                
                     resultPanel.add(jsp);
               resultPanel.revalidate();
          } catch (IOException e1) {
                   System.err.println(e1);               
                   System.exit(1);
          }//end of catch      
     }//end of function
}//end of class 'ButtonHandler'

pkwooster
Thanks for ur explanation. I I added invokelater and get some exception: "Cannot call invoke and wait from evene dispatcher thread." How can I eleminate that. Pls reply.
public class ButtonHandler implements ActionListener {
     GUIPanel guiPanel;
     ButtonHandler(GUIPanel gp){
          guiPanel=gp;
      public void actionPerformed (ActionEvent e){                    
          JButton button = (JButton)e.getSource();
          if(button == guiPanel.excButton){
               JTextArea jta = new JTextArea();
               jta.setFont(new Font("Serif", Font.BOLD, 14));
                 jta.setEditable(false);
               JScrollPane jsp = new JScrollPane( jta,
               JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS );
               resultPanel.removeAll();     
               jta.append("Please wait while we retrive the Information... ");
               resultPanel.add(jsp);
               resultPanel.revalidate();
               runBatFile(); // run the batch file
                        parseResult();     //show the output               
          if(button == guiPanel.closeButton){
               System.exit(0);
      }//end of fucntion
     public void runBatFile(){
          try {
               SwingUtilities.invokeAndWait(new Runnable() {
               public void run() {                
                    Process p=null;
                    try {             
                           p = Runtime.getRuntime().exec("abaqus_license.bat");               
                    } catch (IOException e1) {System.err.println(e1);}//end of catch
           } catch(Exception e) {;}
          }//end of function
     public void parseResult(){
          ;//do something
     }//end of function
}//end of class 'ButtonHandler'

Similar Messages

  • How to put in process chain a function to desactivate aggregates

    Hi all, how can i do  to put in process chain a function to desactivate aggregates
    thanks

    Hello Jorge,
    You can use a ABAP process type and call the program
    SAP_AGGREGATES_DEACTIVATE to deactivate the aggregates.
    Similarly if you want to fill through an ABAP program you can use
    SAP_AGGREGATES_ACTIVATE_FILL
    You can refer this doc
    [Aggregates - Initial Fill: Custom Approach to Fill in Parallel|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/7005b9ff-6871-2910-009e-f4d214cbe81f]
    You can also refer this Wiki
    [Useful ABAP Programs & Function Modules in SAP BI - Business Intelligence|https://www.sdn.sap.com/irj/sdn/wiki?path=/pages/viewpage.action?pageId=35458]
    Thanks
    Chandran

  • How to put MBA in 'Safe Sleep' mode.

    How do you put MBA in Deep Sleep 'Safe Sleep' mode? I have been reading many postings here and on the internet and am not getting a definitive answer. The whole topic seems to be rather confusing. Does someone have a simple answer in achieving hibernation sleep on the MBA?
    Maybe someone has an example of what they are doing and how they are doing it?
    Thanks and I look forward to your replies.
    ...Bruce
    Message was edited by: BGmail

    The best I found was using this program: http://blog.kaputtendorf.de/2007/08/17/hibernation-tool-for-mac-os/
    I've placed it on my dock and use it when I want to hibernate. I liked the machine's default sleep behavior on the closing of the lid so I did not want to change it.
    However, I found that the rebooting is actually faster than hibernation. It takes about half the time to boot than it takes while waking up from hibernation/deep sleep. I compared it with no applications running, which tells me why Apple did not put Deep Sleep in their menus because it is poorly implemented and does not get you the same advantages, which say as you'd have, on a Windows platform.
    For example, before Mac I was using a Windows based laptop computer and waking up from hibernation was a big difference in life. My machine would come out from hibernation in 15-20 seconds - compared to 75-90 seconds it took to boot. Waking up from Sleep was comparable to Apple but the battery would be drained much quickly so I never used it for longer 'off' periods. Here my MBA loses about 1.5% of its charge every hour during sleep, so I don't mind leaving it sleeping if I know I'll be charging it the next day.
    Since Mac's boot time is quite good so probably it'd make more sense to use sleep during the working hours and shutting it off overnight. Hibernation as a practical option does not exist for me if it takes longer than booting.

  • HOW TO PUT THE MINI TO SLEEP

    HEY ALL,
    iPod mini 4GB purchased 5-05 (so whatever generation that is)
    I have found a way to put my mini to sleep....it still will not show up on FireWire ports, but at least this way it will hold a charge...
    Holding down Play/Pause DOES NOT WORK. This may be a glitch in iTunes 7.
    Go to EXTRAS> CLOCK>SLEEP TIMER
    You will find it is off if you have updated your iPod. Set it to the desired time (I used 15 min) and the mini will power off after that time.
    Hope this helps

    This can't be part of iTunes, it has to be part of the iPod Restore formatter.
    Which version of restore did you use? If this true (holding down the button doesn't put it into "sleep" mode), I would want to avoid that version.

  • How to put the display to sleep in Mac OS Lion using keychain?

    I use to be able to turn off my displays by hitting "lock screen" in keychain access in Snow Leopard. Now, when I hit it in Lion, it goes to screen saver. It was great being able to turn off the display at night, before going to bed.
    Anyone know a work around WITHOUT going to System Preferences -> Desktop & Screen Saver -> Screen Saver -> Hot Corners... -> Pick a corner -> Select "Put Display to Sleep"? I do not want to use hot corners.
    I want to lock computer using keychain and the displays go to sleep.
    Hopely someone knows of some plist that can be written to-to put the display to sleep.

    windmarble wrote:
    I use to be able to turn off my displays by hitting "lock screen" in keychain access in Snow Leopard.
    Really? Want to show me that button or setting that allows that? AFAIK, System Preferences->Security->General->is where you set that when the machine sleeps or screensaver activates. Accordingly, I'm only aware of a hot corner triggering those two options and the behavior remains the same in Lion, even though the prefPane's name is slightly changed.

  • How to stop main process in BADI

    Hi All,
    I am using WORKORDER_UPDATE BADI to do some planning data manipulations..
    If something gone wrong in planning data manipulations user should get error message and should stop main process i.e. update of production order.
    Is it possible with in BADI?
    If yes ..please help me with your suggestions..
    Thanks

    Hello,
    it would be possible in the method AT_SAVE - if you do so, you would have to raise the exception ERROR_WITH_MESSAGE.
    But it's the only method where you can do so...
    Regards Wolfgang

  • This is so basic: How do you turn off Apple TV, or do you just exit by changing the Input back to regular TV? When I put Apple TV to sleep, I had to log in again, a very tedious process with that awful "announcer" for the hearing impaired (how to remove?)

    This is so basic: How do you turn off Apple TV, or do you just exit by changing the Input back to regular TV? When I put Apple TV to sleep after I installed it, I had to log in again, a very tedious process with that awful "announcer" for the hearing impaired (and how to remove that?).

    Welcome to the Apple Community.
    The Apple TV will put itself to sleep. I'm not sure what you needed to log into again, but you shouldn't have to. Do you have a little more detail about what happens.

  • Sometimes after putting my iMac to sleep, I can't get it to wake up and have to turn it off at the mains. Any ideas why?

    Sometimes after putting my iMac to sleep, I cannot get it to wake up again. It's as if it's shut down and I have to turn it off at the mains and restart it.  Any ideas why? Does this keep happening to anybody else?

    That message means that you have to restore the iPad now. Something went wrong. You need to restore the iOS software and then restore from the backup.
    Read this carefully and follow the instructions. Make sure that you restore from your backup at the end of the process. That is covered at the bottom of the support article.
    http://support.apple.com/kb/HT1414

  • How can I put my iMac to sleep after it has finished downloading or uploading something?

    For example: I have some photos and videos that I want to send to a friend. I'm uploading them to a site to do this, and they're quite big files (250 MB).
    I'd like to do this at night, but I don't want to let the computer run all the night through, when this maybe only needs a few hours.
    I can only guess how long it will take (judging by the time it tells me that it will take, if available), and then I can set the computer to go to sleep after X hours or minutes.
    Can I not just simply set it in a way that it goes to sleep automatically after the process is finished? Like, if there's a connection to the internet, that is being used (downloads, uploads), then it shouldn't go to sleep, else it will interrupt the upload, and I can start again.
    Also, I have an iMovie update now, which is over a GB of download.
    I may be mistaken, but I have the feeling that for some Apple programs, it actually keeps the computer awake until the process is done. But it isn't the case with all programs, only with some.
    It's really annoying. Does anyone know a solution? I know that there's this box that you can tick, that says something like to keep the computer from going to sleep if there's a network connection, but in earlier OS this was actually working! Now it's 100% useless.

    You can just set your Mac to sleep using the Energy Saver in System Pref.  Set it to sleep after say, 2 mins of inactivity then check the Put Hard Disk to Sleep setting too.  It won't sleep while you are down/uploading.

  • HT201304 Visa has changed for the purchase of Apple products, i did not know how I put the new MasterCard number to finish the process of buying products Thank you

    Visa has changed for the purchase of Apple products, i did not know how I put the new MasterCard number to finish the process of buying products Thank you
    i have ibad mini
    and iphone4
    laptop sony
    can you sent for me the anser

    Changing Account Information  >  http://support.apple.com/kb/HT1918

  • HOW TO SHOW JLABEL IN JDIALOG USE TIMERTASK WHILE MAIN CLASS IS SLEEPING?

    I have done a code below and it is working but the only problem is when the main program start to sleep by use Thread.sleep(10000) for 10 secs and it will prompt out a JDialog contain JLabel inside it with message "Please wait.... program is sleeping.". And when the thread ends the JDialog will auto disappear and it back to the main program.
    The problem is:
    When the JDialog appear, it doesn't show the component so I only be able to view the JDialog window without contain any component. I already use container to add the component into JDialog but it still doesn't show. I only be able to see the JDialog window contain empty component when the main window is sleeping.
    How to make the components also appear in the JDialog when the main program is sleeping?
    Below is the code pls have a try:
    import java.util.*;
    import java.lang.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class testThread extends JFrame
    public static java.util.Timer thisTimer;
    public static doTask a;
    public static testThread tT;
    public Container cMain;
    public Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    public JButton exitBtn;
    public JButton startThreadBtn;
    /** Creates a new instance of testThread */
    public static void main(String args[])
    new testThread();
    public testThread()
    //System.out.println("Start to call JDialog");
    tT = this;
    int realW = (int)screenSize.getWidth();
    int realH = (int)screenSize.getHeight();
    int mainW = 500;
    int mainH = 300;
    setBounds((int)((realW-mainW)/2), (int)((realH-mainH)/2), mainW, mainH);
    setVisible(true);
    exitBtn = new JButton("EXIT");
    exitBtn.setBounds((int)((500-100)/2), (int)((300-50)/5), 100, 50);
    exitBtn.addActionListener
    new ActionListener()
    public void actionPerformed(ActionEvent e)
    System.exit(0);
    // WHEN USER PRESS startThreadBtn it will make the application sleep for 15 secs and pop out JDialog window contain JLabel msg wrote "Please wait... program is sleeping"
    startThreadBtn = new JButton("Start Thread");
    startThreadBtn.setBounds((int)((500-100)/2), (int)((300-50)/5*4), 100, 50);
    startThreadBtn.addActionListener
    new ActionListener()
    public void actionPerformed(ActionEvent e)
    try
    System.out.println("Start to call JDialog");
    a = new doTask();
    thisTimer = new java.util.Timer();
    thisTimer.schedule(a, 0);
    System.out.println("Thread start to sleep first 10 secs");
    Thread.sleep(10000);
    System.out.println("Thread start to sleep second 5 secs");
    Thread.sleep(5000);
    System.out.println("Thread Wake Up");
    a.terminate();
    thisTimer.cancel();
    catch(InterruptedException ie)
    ie.printStackTrace();
    cMain = this.getContentPane();
    cMain.setLayout(null);
    cMain.add(exitBtn);
    cMain.add(startThreadBtn);
    public class doTask extends TimerTask
    JDialog infoDialog;
    public void run()
    System.out.println("TASK IS RUNNING");
    int screenWidth = (int)screenSize.getWidth();
    int screenHeight = (int)screenSize.getHeight();
    int w = 300;
    int h = 200;
    infoDialog = new JDialog(tT, true);
    infoDialog.setTitle("Please Wait!!!");
    Container c = infoDialog.getContentPane();
    c.setLayout(new BorderLayout());
    JLabel infoLbl = new JLabel("Please Wait... Program is sleeping!!!", JLabel.CENTER);
    c.add(infoLbl, BorderLayout.CENTER);
    infoDialog.setBounds((int)((screenWidth-w)/2), (int)((screenHeight-h)/2), w, h);
    infoDialog.setVisible(true);
    public void terminate()
    infoDialog.setVisible(false);
    infoDialog.dispose();
    this.cancel();
    }

    LOUD NOISES.

  • HOW TO SHOW JLABEL IN JDIALOG  WHILE MAIN CLASS IS SLEEPING? (CODE EDITED)

    I have done a code below and it is working but the only problem is when the main program start to sleep by use Thread.sleep(10000) for 10 secs and it will prompt out a JDialog contain JLabel inside it with message "Please wait.... program is sleeping.". And when the thread ends the JDialog will auto disappear and it back to the main program.
    I am using TimerTask to run the JDialog while the main class is sleeping.
    The problem is:
    When the JDialog appear, it doesn't show the component so I only be able to view the JDialog window without contain any component. I already use container to add the component into JDialog but it still doesn't show. I only be able to see the JDialog window contain empty component when the main window is sleeping.
    How to make the components also appear in the JDialog when the main program is sleeping?
    Below is the code pls have a try:
    public class testThread extends JFrame
    public static void main(String args[])
    new testThread();
    public testThread()
    * other code not related is here
    // WHEN USER PRESS startThreadBtn it will make the application sleep for 15 secs and pop out JDialog window contain JLabel msg wrote "Please wait... program is sleeping"
    JButton startThreadBtn = new JButton("Start Thread");
    startThreadBtn.addActionListener
    ( new ActionListener()
    public void actionPerformed(ActionEvent e)
    try{
    doTask a = new doTask();
    java.util.Timer thisTimer = new java.util.Timer();
    thisTimer.schedule(a, 0); // when this code executed, will pop out a JDialog containing JLabel message --> refer to class doTask
    Thread.sleep(10000);
    a.terminate()
    thisTimer.cancel();
    catch(InterruptedException ie)
    ie.printStackTrace();
    public class doTask extends TimerTask
    JDialog infoDialog;
    public void run()
    infoDialog = new JDialog(true);
    infoDialog.setTitle("Please Wait!!!");
    Container c = infoDialog.getContentPane();
    c.setLayout(new BorderLayout());
    JLabel infoLbl = new JLabel("Please Wait... Program is sleeping!!!", JLabel.CENTER);
    c.add(infoLbl, BorderLayout.CENTER);
    infoDialog.setVisible(true);
    public void terminate()
    infoDialog.setVisible(false);
    infoDialog.dispose();
    Why I can not show the JLabel inside the JDialog? The JDialog window is opened but it contain empty component.
    PLEASE HELP ME .... THIS IS VERY URGENT

    I have the complete code and it is working. I can posted it here but it will be longer thats the reason why i shortened the code in here and displaying the important information.
    The problem is the JDialog only will display the JLabel after the thread woke up. Thats mean it is too late for me to display the information. I need the JLabel containing the information to be displayed when the thread is sleeping....
    Below is the complete code:
    you can have a try to recompile it and u will understand what i mean. It is working and the only problem is JLabel component did not displayed in the JDialog.
    Just copy the whole code into the txt file and save as testThread.java and recompile it. Inside the code has one inner class extends TimerTask call "doTask"
    THE CODE START BELOW:
    import java.util.*;
    import java.lang.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class testThread extends JFrame
    public static java.util.Timer thisTimer;
    public static doTask a;
    public static testThread tT;
    public Container cMain;
    public Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    public JButton exitBtn;
    public JButton startThreadBtn;
    /** Creates a new instance of testThread */
    public static void main(String args[])
    new testThread();
    public testThread()
    //System.out.println("Start to call JDialog");
    tT = this;
    int realW = (int)screenSize.getWidth();
    int realH = (int)screenSize.getHeight();
    int mainW = 500;
    int mainH = 300;
    exitBtn = new JButton("EXIT");
    exitBtn.setBounds((int)((500-100)/2), (int)((300-50)/5), 100, 50);
    exitBtn.addActionListener
    new ActionListener()
    public void actionPerformed(ActionEvent e)
    System.exit(0);
    startThreadBtn = new JButton("Start Thread");
    startThreadBtn.setBounds((int)((500-200)/2), (int)((300-50)/5*4), 200, 50);
    startThreadBtn.addActionListener
    new ActionListener()
    public void actionPerformed(ActionEvent e)
    try
    System.out.println("Start to call JDialog");
    a = new doTask();
    thisTimer = new java.util.Timer();
    thisTimer.schedule(a, 0);
    System.out.println("Thread start to sleep first 10 secs");
    Thread.sleep(10000);
    System.out.println("Thread start to sleep second 5 secs");
    Thread.sleep(5000);
    System.out.println("Thread Wake Up");
    a.terminate();
    thisTimer.cancel();
    catch(InterruptedException ie)
    ie.printStackTrace();
    cMain = this.getContentPane();
    cMain.setLayout(null);
    cMain.add(exitBtn);
    cMain.add(startThreadBtn);
    setBounds((int)((realW-mainW)/2), (int)((realH-mainH)/2), mainW, mainH);
    setVisible(true);
    public class doTask extends TimerTask
    JDialog infoDialog;
    public void run()
    System.out.println("TASK IS RUNNING");
    int screenWidth = (int)screenSize.getWidth();
    int screenHeight = (int)screenSize.getHeight();
    int w = 300;
    int h = 200;
    infoDialog = new JDialog(tT, true);
    infoDialog.setTitle("Please Wait!!!");
    Container c = infoDialog.getContentPane();
    c.setLayout(new BorderLayout());
    JLabel infoLbl = new JLabel("Please Wait... Program is sleeping!!!", JLabel.CENTER);
    c.add(infoLbl, BorderLayout.CENTER);
    infoDialog.setBounds((int)((screenWidth-w)/2), (int)((screenHeight-h)/2), w, h);
    infoDialog.setVisible(true);
    public void terminate()
    infoDialog.setVisible(false);
    infoDialog.dispose();
    this.cancel();
    ******************************************************************************************************************************************************************************************************************************************

  • How to put q10 to sleep with power/lock button

    Hello! Love some help on this seemingly simple problem....
    I am new to BlackBerry from iphone and am very happy except I have to wait for the 30 second time out before I put into my pocket... because I can't figure out how to put it to sleep or at least activate the lock screen instantly.
    On or off the settings/lockscreen option doesn't seem to do anything. I have not a password lock activated and prefer not too if possible.
    I am on the latest os fyi.
    Can anyone help??
    Thanks ewan

    I'll be happy to help you with this.
    You can put your Q10 to sleep simply by pressing (and not holding) the power button up top. A quick press will put it to sleep.
    I hope that helps you.  
    - If my response has helped you, please click "Options" beside my post and mark it as solved. Clicking the "thumbs up" icon near the bottom of my response would also be appreciated.

  • How putting my mac to sleep with the display closed????

    How putting my mac to sleep with the display closed????

    MBP does not sleep when display is closed?
    For:   A portable Mac doesn't appear to respond properly when you close or open the lid.
    Reset SMC.  http://support.apple.com/kb/HT3964
    Choose the method for:
    "Resetting SMC on portables with a battery you should not remove on your own".

  • How Put the computer to sleep with a "F key?

    Hi,
    How do you Put the computer to sleep with a "F key?
    I do remember seeing a version of osX where there was a (say) "F2" key next to the Apple>Sleep pull down menu.
    with 10.2.8 or 10.3.9 is there a way to set up a "F" key instead of using the pull down menu?
    I looked into the system preferences> keyboard & mouse but no luck. The sys Pref> keyboard & mouse is different on 10.2.8 that on 10.3.9.
    An neither one has an option to use an F key to put to sleep.
    help!
    Michel

    Not an F key command, but here's a keyboard command.
    http://www.apple.com/pro/tips/quicksleep.html
     Cheers, Tom

Maybe you are looking for

  • Can I use iCloud Keychain without a smart phone?

    I do not have a phone that can receive messages.  That what computers are for.  Can I use iCloud Keychain? Thanks, HAK

  • Win 8.1 machines printer goes offline very frequently

    Hi, We have some users are in win-8.1 OS, more frequently they have printer offline issue. But, this is not for all the win-8.1 OS users. Only few of the peoples sometime printer is working well & sometime it went automatically offline. Any solution

  • Sap admin problem

    I applied a new patch to the sapadmin (containing bw 3.0b patch 22,sapsetup patch 23 and sapgui patch 66) - i installed it remotely to all the workstations - after installing remotely i discovered a problem - is thare a way to uninstall the patch fro

  • How to fix the width of sorting column about adf table ?

    I develop project with ADF in jdeveloper. When click on the sorting column header in adf table,it will adjust the width of the sorting column header.It will make page shifting. How can I do to avoid the adjusting ? How can I do to fix the width of so

  • Is it possible to select specific properties of multiple layers at once?

    I know that you can alter, opacity for example, of multiple layers at the same time by selecting the opacity property of each layer. But what if there are so many layers that you want to select a single property of many layers at once? For example, I