Executable Launcher (top)

Source: Internet
Author: User

An executable file launcher can execute an external executable file repeatedly at certain intervals. if we generate a jar file with source code, it is: Launcher.jar. You can run it with the following DOS command:Java-jar Lib\launcher.jar Getprocessstate.bat5000 indicates that the Getprocessstate.bat file is executed every 5000 milliseconds. source contains 2 files Worker.java and Launcher.java

Worker.java file:

Package Com.teleca.robin;import Java.io.BufferedReader;import java.io.IOException;import Java.io.InputStreamReader; import Javax.swing.JLabel;import Javax.swing.JTextField; Public class Worker extends Thread {private Boolean loop=true;private Boolean paused=false;private int cnt=0;final Private JLabel consoletext;Worker (JLabel lable)    {consoletext=lable;    }private long interval=1000;void SetInterval (long interval)    {This.interval=interval;    }private String executablefilename;void Setexecutablefilename (String file)    {if (executablefilename!=null&&file!=null)     {if (!executablefilename.equals (file))cnt=0;     }Executablefilename=file;    }Public void Dopause ()    {paused=true;    }Public void Doresume ()    {Paused=false;interrupt ();    }Public void Die ()    {Loop=false;    }Public Void Run ()    {While (loop)     {if (paused| | Executablefilename==null)     {try {Thread.Sleep (+);} catch (Interruptedexception e) {//TODO auto-generated catch block//e.printstacktrace ();}     }Else     {BufferedReader stdout = null;try {Process p = null;String line = null;p = runtime.getruntime (). EXEC (executablefilename, NULL, NULL);stdout = new BufferedReader (new InputStreamReader (P. getInputStream ()));While (line = Stdout.readline ()) = null) {System.out.println (line);    }stdout.close ();Stdout=null;} catch (IOException e) {e.printstacktrace ();}finally{if (stdout!=null)try {stdout.close ();} catch (IOException e) {//TODO auto-generated catch blocke.printstacktrace ();}   }cnt++;if (consoletext!=null)Consoletext.settext ("Execute the file" +cnt+ "Times");try {Thread.Sleep (interval);} catch (Interruptedexception e) {//TODO auto-generated catch block//e.printstacktrace ();}     }     }System.out.println ("exit!");    }}

Executable Initiator (top)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.