Results 1 to 4 of 4

Thread: Thread.sleep

  1. #1
    Gog
    Gog is offline Member
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Post Thread.sleep

    Hi all,

    I have problem with Thread.sleep (with syntax) - I am begginer of Java, I need Action which start external application /this works/ and after (x second) will end (Program which start external file.mt2 and after video end, program close), please pre-type my code, i dont understand it very much.

    ActionListener Uvod = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    Timer timer = new Timer();
    try {
    final Process p = Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + "D:\\SSEAS.m2t");
    BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    java.util.TimerTask tt = new java.util.TimerTask() {
    public void run() {
    p.destroy();
    }
    };
    timer.schedule(tt, 30000); // run the method in 30 seconds

    } catch (IOException ex) {
    Error.setText("Error!");
    }
    }
    };

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    First off, Welcome! Second, please use [code][/code] tags when posting code, this helps with readability immensely.

    Second, does your code work properly without the timer? That will help narrow down your issue.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm worried about your calling Runtime.exec in a Swing program on the main Swing thread, the EDT or Event Dispatch Thread, as this can put your entire GUI to sleep. Also you should probably be using a Swing Timer (javax.swing.Timer) instead of a java.util.Timer if this is a Swing program.

    Also, what do you mean by this?
    please pre-type my code

  4. #4
    Gog
    Gog is offline Member
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Default

    quad64bit: Sorry, my fail (code), right - all work well, VLC start SSEAS.m2t (this works) and end but I wanna so that It end when video end (video has 4minutes) -> after 3minutes Process p END. I post you code without Timer or something that.

    Java Code:
            ActionListener Uvod = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    try {
                        final Process p = Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + "D:\\SSEAS.m2t");
                        BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
                                p.destroy();
    
                    } catch (IOException ex) {
                        Error.setText("Error!");
                    }
                }
            };
    Fubarable: yes it's Swing Program, my fail, i used java.util.Timer (I haven't any experience with it).

Similar Threads

  1. Difference between Thread.yield() and Thread.sleep() methods
    By Nageswara Rao Mothukuri in forum New To Java
    Replies: 12
    Last Post: 07-30-2010, 05:37 PM
  2. how to reduce the thread sleep time and wake up the thread
    By baktha.thalapathy in forum Threads and Synchronization
    Replies: 2
    Last Post: 06-24-2010, 07:36 PM
  3. thread.sleep
    By jc5 in forum CLDC and MIDP
    Replies: 0
    Last Post: 09-02-2009, 11:51 PM
  4. Sleep in thread
    By jithan in forum New To Java
    Replies: 1
    Last Post: 08-27-2008, 02:27 PM
  5. How to use the sleep and thread?
    By jiuhu in forum Java Applets
    Replies: 4
    Last Post: 08-07-2007, 02:56 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •