How to terminate and restart a java program from a controling java program?

I have a situation where my program needs to run exactly once each one
hour. This is a huge program that creates a lot of threads and opens
lot of resources. After one hour has lapsed, I want to terminate this
program (as if Exit(0) was performed on it or as if Ctrl C was pressed
from the command line to terminate a running program) and then run it again and so on repeat the cycle each hour. This will guarantee that
all the resouces taken by the programs are freed or if some threads were still blocked on i/o, are indeed terminated each hour.
The java program does not have any user interface and it is run from the
command line.

if you can change the program to be controlled, you could make it listen for commands on some networkport for shutting it down.
If this is not an option you could start OS programs to kill the first program. On Unix System kill will do, but you need the process id so you'd need another os call ...
You could do the os calls in two ways
a) execute shell commands (search the forum on how to do that
b) write a little C wrapper for the os call so you can call them from JNI (Java Native Interface)
I do not know of any way do this kind of thing directly
regards
Spieler

Similar Messages

  • How to Stop and restart the midtier?

    Hello All,
    I have installed Oracle AS (Infraturcture & middle tier , BI & Forms) on same Linux box.i.e: Oracle As 10.1.2.0.2 (Rel 2, x86 for Linux), SLES 9
    Here is my question:
    How to Stop and restart the midtier?
    Regards,
    DN

    biforms.sh
    export ORACLE_HOME=/opt/oracle/biforms
    export OH=$ORACLE_HOME
    export PATH=$OH/bin:$OH/opmn/bin:/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/java/bin
    export ORACLE_SID=ORCL
    export LD_LIBRARY_PATH=$OH/lib:/usr/openwin/lib:/usr/dt/lib:/usr/lib:/tools/lib
    infra.sh
    export ORACLE_HOME=/opt/oracle/infra  <-- or correct one!
    export OH=$ORACLE_HOME
    export PATH=$OH/bin:$OH/opmn/bin:/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/java/bin
    export ORACLE_SID=ORCL
    export LD_LIBRARY_PATH=$OH/lib:/usr/openwin/lib:/usr/dt/lib:/usr/lib:/tools/libAs you see, only the first row differs from these two scrips. Because I'm lazy, I usualy set export OH. Under certain circumstances you might want to add DISPLAY to biforms.sh. Set it to localhost:0 or whatever is correct.
    Martin

  • How to execute a Perl program from within a Java prog

    How do I execute a Perl program from within a Java program.
    Lets say the Perl program that I want to execute is 'abc'. Now, 'abc' requires some input that I want to give it from within the Java program. How do I do it?
    And finally, how do I execute that Perl program from within the Java program.
    If I execute the Perl program alone then I do it in the following way -
    perl abc inp1 inp2 inp3
    where inp1, inp2, inp3 are inputs to the Perl program. I will not be able to change or modify the coding of the Perl program - 'abc' as I do not have access to its code. Its a kind of an application whose usual method of execution is in the above shown way. So, how do I execute 'abc' from within a Java program.

    what part of don't crosspost, don't you understand?
    http://forum.java.sun.com/thread.jsp?forum=4&thread=427193

  • How to use AND,OR,NOT condition in Pattern Matching in java

    how to use AND,OR,NOT condition in Pattern Matching in java
    Please anyone give example..

    Stop asking these stupid vague questions and do some of your own research.
    Start here:
    http://www.regular-expressions.info/
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html

  • How to Stop and restart the OC4J_BI_FORMS?

    I have Oracle AS 10.1.2.0.2 (Rel 2) installed. (Infratsructure & BI & Forms) on same computer.
    my question is :
    How to Stop and restart the OC4J_BI_FORMS?
    Regards,
    DN

    Just as any other OC4J:
    opmnctl stopproc -process-type=OC4J_BI_FORMS
    opmnctl startproc -process-type=OC4J_BI_FORMS
    or
    opmnctl restartproc -process-type=OC4J_BI_FORMS
    cu
    Andreas

  • How to run java programs from a master java program?

    Hello,
    I have several java programs which run from the command prompt. I am seeking help with code for starting java programs from within a java program. For example, a program called master.java works something like this:
    import java.*;
    create connection pool
    create variables and result sets
    start/run slave1.java (var1, var2);
    start/run slave2.java (var3, var4, var5);
    start/run slave3.java (var1, var4);
    end of program master.java
    Each of the slave.java programs will run for up to an hour. I do not want the master.java program to pause for each slave program to stop. Instead, the master program will keep running and multiple slave programs will be running simultaneously with the master program. When a slave program starts, it is on its own. Also, if possible, I would like to have each of these slave.java programs open in a new separate command window, so I can observe each slave program running in separate windows.
    Any suggestions for code or helpful documentation are greatly appreciated.
    Thank you,
    Logan

    Thank you all.
    At the bottom of master.java I have successfully started a batch file with these lines:
    String jcmd = "cmd.exe /c start c:/data/simulations/MsgViewCount2.bat";
    Process proc = Runtime.getRuntime().exec(jcmd);
    But I still cannot get a java program to start. Here is one variation I have tried:
    String [] cmdArray = new String[2];
    cmdArray[0] = "java";
    cmdArray[1] = "slave1";
    Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec(cmdArray);
    This compiles, and no errors occur, but nothing happens.
    Regarding this comment:
    Why Runtime.exec? Either make the slaves Runnable or
    just call their main() methods.
    Oh, I see. Sepearate output. :PNone of the slave.java programs have any output.
    Thanks again.

  • Executing C program from with a java program

    How do you call a c program from within a java program, and parse arguments into that program and return something.
    Cheers for any reply...

    Read http://www.javaworld.com/jw-12-2000/jw-1229-traps.html

  • Executing a Java Program from within a Java Program

    I need to execute the following Java Program from withing another Java Program. The office toolbar command line is
    D:\WINDOWS\system32\java.exe -cp E:\Development\Eclipse\UpdateServer\Classes -server -showversion UpdateServer
    I can find no combination of ProcessBuilder commands, including those that include "Cmd.exe /c" that will make this program run from within another Java Program. All the examples I can find only show how to run Windows *.exe programs. I keep getting error 123 from ProcessBuilder.start(), but I can find no documentation for error 123.

    Assuming your code didn't get mangled by the forum
    (it's missing one "), it may be that your "-cp
    E:\\Develop.." argument is getting quoted as it has a
    space in it; try passing "-cp" and "E:\\Develop..."
    as two arguments.That worked; specifically the following tested OK:
    ProcessBuilder pb = new ProcessBuilder("D:\\WINDOWS\\System32\\Java.exe", "-cp", "E:\\Development\\Eclipse\\UpdateServer\\Classes\\", "-server", "-showversion", "UpdateServer" );
    pb.directory(new File("E:\\Development\\Eclipse\\UpdateServer\\Classes\\"));
    try{
         Process p = pb.start();
         InputStream is = p.getErrorStream();
         InputStreamReader isr = new InputStreamReader(is);
         BufferedReader br = new BufferedReader(isr);
         String line;
         while ((line = br.readLine()) != null)
              System.out.println(line);
         p.waitFor();
    }catch(IOException ioe){
    I was sure I tried that exact same code before, and it did not work, but now it does, at least at the top level (when it is in main of a test program). I will have to wait to try it until later when it is buried deep in a subroutine.

  • Executing a Perl program from within a Java prog

    How do I execute a Perl program from within a Java program.
    Lets say that the Perl program that I want to execute is 'abc'.'abc' requires some input that I want to give from within the java program. How do I do that? Then I want to execute the Perl program from within the Java prog. How do I do it?

    don't crosspost.
    http://forum.java.sun.com/thread.jsp?forum=31&thread=427211&tstart=0&trange=100

  • How to drag and drop the af:inputNumberSpinbox in the control panel

    Hi,
    I am using jdev 11.1.1.4.0
    I need the component as <af:inputNumberSpinbox> . Create a data model and how to drag and drop as inputNumberSpinbox in the data control.
    normally drog and drop the particular attribute as inputText box only. I want <af:inputNumberSpinbox>.
    anythig want to change in the view object control hints itself. help me.
    Regards,
    ragupathi S.
    Edited by: Ragu on Jun 22, 2011 4:45 PM

    Hi,
    Can't you drop it as an inputText and then change it in the source to inputNumberSpinbox?
    Regards,
    Stijn.

  • How to find and remove obsolete table entries from /SAPAPO/MATKEY table in EWM System.

    Hello,
    How to find and remove obsolete table entries from below tables in EWM System.
    /SAPAPO/MATKEY
    /SAPAPO/MATMAP
    /SAPAPO/MARM
    /SAPAPO/MATLOC
    /SAPAPO/MATMOD
    /SAPAPO/MATRQ
    /SAPAPO/MATLOTSZ
    Thank you,
    Pravin

    Pravin,
    First, tell me how you determine that these entries are 'obsolete'.
    Removing master data from SCM can usually be done using transaction WUF; however, you have to ensure that it is not re-sent to the SCM system, or you are just wasting your time.
    Best Regards,
    DB49

  • Compiling java code from a running java application

    How does compiling of java code from a running java application work?
    I found a class: com.sun.tools.apt.main.JavaCompiler
    but cannot find any documentation of how this class works.

    How does compiling of java code from a running java
    application work?Probably most reliably using Runtime.exec().
    I found a class:
    com.sun.tools.apt.main.JavaCompiler
    but cannot find any documentation of how this class
    works.For a purpose. You are not supposed to use this class. With the next JRE release or implementation, it might not exist anymore - it's not part of the standard API.

  • How to make users to select the date from calendar control my making the date field read only in date time control in external list in sharepoint 2010

    How to make users to select the date from calendar control only, by my making the date text field read only (don't want to let users type the date) in date time control in external list in sharepoint 2010. I am looking for a solution which can
    be done through sharepoint desginer / out of the box.
    thanks.

    Congratulate you got the solution by yourself. I am new to a
    WinForms calendar component, I feel so helpless on many problems even I'd read many tutorials. This question on the
    calendar date selection did me a great favor. Cheers.

  • How to create and install a toolbar to a browser using java

    Hi all,
    Can any one guide me about how to create and install toolbar to a browser using java ??
    please any one help me about this,i am not getting any idea about this..
    Thanks and Regards
    Sandesh S

    I doubt you can. Those browser toolbars are done by implementing to an API provided by the browser. That API, I don't believe, is provided via Java. But of course, that would be entirely up to the browser, not Java.

  • Imports seem to be hanging how to stop and restart

    Hi,
    I am workin on transports using transaction code STMS. I submitted the imports many hours ago and it seems that they are hanging or stopped. The Trucks are still in the column status. I do see some objects got imported but some did not.
    How can I fix this and restart the import because the Trucks are tere and I can't restart? Or how do I stop the imports or should I just let it continue? It has been hours now.
    Thanks

    hi Will,
    To change the status of the transport, you can goto STMS -> Import Overview -> select the system -> select your request and after that press Ctrl-F8 (Import Monitor). Under the 'scheduling monitor' you'll see your transport request is in running mode, delete this request.
    After you delete go back to previous screen the list of transport request, click on Refresh, you'll see your request will be in 'green' status again. ready for re-import again.
    Also check the note Note 71353 - Transports hang during background steps which may apply to your condition. Hope this help you.
    Regards,
    Mark
    PS. appreciate your point:)

Maybe you are looking for