Stop the method Execution.

Hi..
I have a method call to make a credit card payment.sometimes it takes so much times.If that process takes more than 10 minutes,
I want to stop that method execution.I have implemented the TimerTask to check the execution time and stop..but I don't have a idea to stop that processing method...
can anyone give me a suggetion.
Regards
Amila

Hi,
You may have a look at this thread [http://forums.sun.com/thread.jspa?threadID=5347956&tstart=0]
I changed the suggested code a little to make it (hopefully) suitable for your use case. Note that the long running task communicates to its invoker via System.out.
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
public class TaskDispatcher {
    private static long lengthy = 10000;
    public static void main(String[] args) {
     SwingUtilities.invokeLater(new Runnable() {
         @Override
         public void run() {
          new TaskDispatcher().createGUI();
    private JTextPane textPane;
    private JLabel message;
    private Process process;
    private Action kill = new AbstractAction("Kill") {
     private static final long serialVersionUID = 1L;
         this.setEnabled(false);
     @Override
     public void actionPerformed(ActionEvent event) {
         destroy();
    private Action dispatch = new AbstractAction("Dispatch") {
     private static final long serialVersionUID = 1L;
     @Override
     public void actionPerformed(ActionEvent event) {
         dispatch();
    public void createGUI() {
     JFrame frame = new JFrame();
     textPane = new JTextPane();
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     message = new JLabel("Status", JLabel.CENTER);
     JToolBar toolBar = new JToolBar();
     frame.add(toolBar, BorderLayout.PAGE_START);
     frame.add(new JScrollPane(textPane), BorderLayout.CENTER);
     frame.add(message, BorderLayout.PAGE_END);
     toolBar.add(dispatch);
     toolBar.add(kill);
     frame.setSize(400, 400);
     frame.setLocationRelativeTo(null);
     frame.setVisible(true);
    private void appendLine(String line) {
     Document doc = textPane.getDocument();
     try {
         doc.insertString(doc.getLength(), line + "\n", null);
     } catch (BadLocationException e) {
         e.printStackTrace();
    private void destroy() {
     kill.setEnabled(false);
     process.destroy();
     dispatch.setEnabled(true);
    private void dispatch() {
     dispatch.setEnabled(false);
     try {
         textPane.setText("");
         launch();
         kill.setEnabled(true);
     } catch (IOException e) {
         e.printStackTrace();
         dispatch.setEnabled(true);
    private void handleErr(final Process process) {
     new Thread(new Runnable() {
         final BufferedReader errReader;
          errReader = new BufferedReader(new InputStreamReader(process
               .getErrorStream()));
         @Override
         public void run() {
          try {
              String line = null;
              while ((line = errReader.readLine()) != null) {
               System.err.println("Other JVM: " + line);
          } catch (Throwable t) {
              t.printStackTrace();
          } finally {
              try {
               errReader.close();
              } catch (IOException e) {
               e.printStackTrace();
     }).start();
    private void handleOut(final Process process) {
     new Thread(new Runnable() {
         final BufferedReader outReader;
          outReader = new BufferedReader(new InputStreamReader(process
               .getInputStream()));
         @Override
         public void run() {
          try {
              String line = null;
              while ((line = outReader.readLine()) != null) {
               appendLine(line);
          } catch (Throwable t) {
              t.printStackTrace();
          } finally {
              try {
               outReader.close();
              } catch (Throwable t) {
               t.printStackTrace();
     }).start();
    private void launch() throws IOException {
     final String command;
     command = "java -cp \"" + System.getProperty("java.class.path") + "\" "
          + LengthyTask.class.getCanonicalName() + " \"" + lengthy + "\"";
     process = Runtime.getRuntime().exec(command);
     message.setText("Process is running");
     handleOut(process);
     handleErr(process);
     new Thread(new Runnable() {
         @Override
         public void run() {
          try {
              int rc = process.waitFor();
              kill.setEnabled(false);
              if (rc != 0) {
               appendLine("Exit code " + rc);
              dispatch.setEnabled(true);
              message.setText(rc == 0 ? "Completed successfully"
                   : "Problem exit code: " + rc);
          } catch (InterruptedException e) {
              e.printStackTrace();
     }).start();
}Piet

Similar Messages

  • How to stop processRequest method execution second time in CO

    Hi all,
    I have a Requirment like to stop ProcessRequest method execution In my controler when i click the button on my page
    Regards,
    Shiva

    Hi Shiva,
    You can make use of session parameters..
    When you click on a button ?? why will the page go to PR method ??
    By default it goes in PFR method.
    Anyways if you are redirecting it to the same page : u can make use of below methods for the same to control the execution of methods in PR.
    While coming back to PR method : check the parameter value.. & make sure that..no methods are executed in it.
    PR Method
    String dieFromUpdate = pageContext.getParameter("DieValue");
    if(dieFromUpdate!=null)
    make use of this condition and execute the statements..
    PF Method
    String Die ='IN PF Method " ;
    pageContext.putParameter("DieValue", Die);
    Regards
    Sridhar

  • How to Stop the method Action When an Exception Occur in other Method

    Hi All ,
    public void action( Event clientEvent) {
    startAction();
    JOptionPane.showMessageDialog(null, getDocumnetId());
    how to Stop the method action ( "action" ) if an exception occur in the method ("startAction")
    ( if the exception occur we doesn't need to show the JOption Message )

    Hi,
    try FacesContext.getCurrentInstance().renderResponse();
    Frank

  • How to stop the Report to Execute in Dashboard

    Hi all
    I have a Date Prompt and unless i enter date into the prompt, my Report should not be executed.
    I am not allowed to use "Display Results -> link in the Dashboard"
    Is there any mechanism to stop the report execution till I enter data in the prompt?
    Thanks in adv.

    There are couple of options.
    In the report add the filter condition date is null and also make date is prompted. So initially the report will show "No results" . So you can format the "No Results" view in the report by adding a appropriate message.
    So the initial display would be your custom message. Once you select the date in the prompt it will fetch you the appropriate results.
    The same can be done using Guided Navigation also. Just reference a source request(just some report which gives no results) if the request returns rows. Apply this property to the section where your actuall report is placed and that will also give the same.
    The option 1 is best and easy solution
    hope it helps
    Prash

  • How to Stop the powershell command execution in C#

    I am executing powershell command synchronously. Binded a eventhandler, which
    runs successfully when data is emitted by pipeline. When some condition met, i wish to stop powershell command execution,
    but when i call pipeLine.Stop(), program just hangs indefinitely. May i know what is going wrong?
    Command shellCommand = new Command("Get-MsolUser");
    Pipeline pipeLine = powerShellRunspace.CreatePipeline();
    pipeLine.Commands.Add(shellCommand);
    pipeLine.Input.Close();
    pipeLine.Output.DataReady += delegate(object sender,EventArgs args) {
    try {
    PipelineReader<PSObject> output = sender as PipelineReader<PSObject>;
    if (output != null) {
    bool isCompleted = false;
    while (output.Count > 0 && !isCompleted) {
    PSObject pso = (PSObject)output.Read();
    isCompleted = addDataDelegate(pso);
    if (isCompleted) {
    pipeLine.Stop(); //HANGS HERE
    log("JUST STOPPED PIPELINE..");
    } catch(Exception ex) {
    log(ex.ToString());
    pipeLine.Invoke();

    You may need to switch to InvokeAsync. I can't find any documentation on this, so it may come down to trial and error, but the synchronous Invoke method may not be playing well with attempts to call pipeLine.Stop().

  • Stop the execution of main for 2 more seconds

    hi,
    I would like to stop the execution of the main program for few seconds and resume again.
    i tried
    try
                        this.wait(90000000);
                   catch(Exception e)
    but did not work
    could some give any other suggestions
    thanks
    jag

    Also, it's better to catch the specific Exception that the Thread.sleep method throws.
    (InterruptedException)
    And it's usually good to output any exception messages, so you can see what's going on.
    Instead of empty catch brackets, it's better to write e.printStackTrace();
    (where e is the name of your caught Exception...)
    cheers!
    lutha

  • How to run a do-while loop on the 2nd execution after a stop on failure occurs?

    I am trying to use the Stop on Failure process model callback from the TestStand Examples.
    If a step fails within a Do-While loop and the test is terminated, the second time the test is run (continuing to the Next UUT in the process model), the condition for the do-while loop is checked first before it ever enters the loop. This is incorrect because the Do-While loop should execute once and then check the "while" condition.
    Also, If I was to stop the execution altogether and then restart the test (instead of continuing with the Next UUT), it runs the loop once, then checks the "while" condition.
    I'm not sure if I am describing this clearly enough. The execution seems to flow like this:
    Start test
    Do
    NumericTest step FAILS  -> terminate
    Next UUT starts
    While (condition is false and skips over Numeric Test step).
    So it seems that TestStand thinks it's still within that Do-While loop on the second execution and whatever runtime variables are not reset correctly.
    Is this a TestStand bug?  It happens in both TestStand 3.1 and 3.5.
    Is there any way around this?
    Thanks for any help.

    If it is what I think it is, it is a bug. Try unchecking Sequence Properties>>Optimize Non-Reentrant Calls to This Sequence and please tell me if that fixes it.

  • How can I stop the execution on a JSP page and start it again

    Hi
    I am making a program that simulates how to manage transactions when accessing a database by using locks. I have run into a problem and I hope someone has the time to help me.
    When a user does an update the transaction commits and releases its locks when the program executes
    <%stmt.executeUpdate("commit!"); %>
    I need to put a break in to stop the program executing this statement, to illustrate the lock is set correctly.
    I have tried to put in an alert box but this does not prevent the rest of the java code being executed.
    I have tried to use prompt boxes, JavaScript functions, but these functions cannot have any java code in them.
    I have tried using the java.swing JOptionPane boxes but this didn?t work either
    I have tried to get input from the user but I don?t know how to retrieve this data on the same page. (As far as I know you have to use submit and even refresh the page or retrieve it on the next page).
    Does anyone know how I can stop the execution on a JSP page and start it again (on same page)
    Mette

    I already have another client (Tomcat jsp application) running and it throws a SQLException correctly when I don�t put in a commit=true statement and don't close the database connection.
    But the problem is how to get the code above to stop to illustrate I have set this lock.
    I have tried to use the JOptionPane but because my program is running in a web browser I cannot use the JOptionPane dialog box.
    I have tired using an alert box but it executes the commit statement before the alert box is dispayed. So this does not work
    While (i < 2)
    if( i==1)
    %>alert(�The transactions commits when you press Ok�); <% //what it to stop execution here
    else
    stmt.executeUpdate(�commit�);
    I am not using threads so I cannot use the sleep function.
    I am using mysql and have already configured it to detect deadlocks and how long to wait for locks.
    Thanks for your help
    Mette

  • Error in crawl log "Error while crawling LOB contents. ( Error caused by exception: Microsoft.BusinessData.Infrastructure.BdcException The shim execution failed unexpectedly - The method or operation is not implemented..; SearchID "

    Hi 
    I get the following error in my crawl logs
    "Error while crawling LOB contents. ( Error caused by exception: Microsoft.BusinessData.Infrastructure.BdcException The shim execution failed unexpectedly - The method or operation is not implemented..; SearchID "
    Because of this i suspect, the search results are not including those aspx pages marked as "Hide physical urls from search".
    This error is not available in the another environment where the aspx pages are coming in the results.
    Thanks
    Joe

    Hi Joe,
    Greetings!
    Reset the index and re-crawl. That usually clears it
    If you are using NTLM authentication, then make sure that you specified the PassThrough authentication for crawling
    Probably you need to debug the BDC code that underlies the external content types.
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/41a86c43-151d-47cd-af73-967a4c940611/lotus-notes-connector-error-while-crawling-lob-contents?forum=sharepointsearch
    Please remember to click 'Mark as Answer' on the answer if it helps you

  • I updated to itunes 10.6 but now it won't open as it says it stops working because of the Data Execution Prevention

    I recently updated toitunes 10.6 but now it won't open as it says it stops working because of the Data Execution Prevention and i've followed the windows help and everything but still can't get it to work. i usually never have a problem when i update.

    I had the same issue after my recent update of iTunes.  I didn't update Quicktime 'cuz I don't use it much (or at all).  On another thread discussing the same issue, I saw that the Quicktime installation can affect iTunes.  So I downloaded the latest Quicktime, installed, redooted - issue fixed (for now). 

  • Stopping the execution in between

    Hi,
    I am using a Event structure to Start and Stop the test. In the Start event i will be having a stacked sequence which consists of many sequences. In the Stop Event I will be stopping the execution. If I press Start button the sequence under this event will start running. I want to Stop the execution or skip the next set of sequences in between the sequence. During this I lose the control over the GUI and I cannot do anything until the sequence under the Start event is completed. I can stop the execution by pressing the abort button but i want do it programmatically.
    Regards,
    Rajashekar

    Here you go...your code with state machine implementation. If you implement it this way, you can definitely take care of the case that you have mentioned.
    Example in LV 8.6.
    Adnan Zafar
    Certified LabVIEW Architect
    Coleman Technologies
    Attachments:
    Sample_State_Machine.zip ‏14 KB

  • [important] click current train stop will run the method

    Hi all,
    I have a question about train stop, I have a train with three train stops, and in the second train stop, I have a method bind to this train stop, if user navigate to the second train stop, this method will run, but in the second train stop, I found that I still can click this page's train stop in the train stop navigation, so this method will execute each time when I click the train stop. Do we have some problems to avoid the issue, I don't want to this method run when click the current train stop, but only run when other train stops navigate to this train stop. Thanks so much!
    Allen

    Thanks for your reply, Arun, my Jdev version is 11.1.1.5, I don't add a switcher component to execute the method, about refreshCondition, it's a attribute? how can I set refreshCondition? I want to know, ADF doesn't have a way to resolve the issue? you know, it's bad that allow the train stop clickable in this train stop, we should don't let this bind method run when click the current train stop. Thanks again!

  • How to stop the std SUS method from being called

    Hi
    I am working on SRM - EDI integration for NON SUS vendor.I am using a custom mapping and custom method call in this case.i have placed the logic in the std. mapping BADI - BBP_SAPXML1_OUT_BADI.i am triggering my custom method call in this method only.but i am unable to stop the control flow here after as i need not to trigger the Std. process.
    Regards,
    Durgaprasad Kare.

    Hi Durga,
    The BADI BBP_SAPXML1_OUT_BADI is meant for mapping purposes in the outbound proxy object and cannot be used to control the message flow.
    What I would suggest you to code the custom logic in the BBP_DOC_SAVE_BADI where is you can check the vendor and determine the custom message needs to be trigerred. Besides you have a check at XI level to block those mesages that are not needed.
    Regards
    Kathirvel

  • Stop the execution for Some seconds

    I want to stop the execution for some second , Basically
    i want some funtion which will wait for specified period .
    it should work like Inkey() in foxpro .
    I have tried timer , pause but that does not solve the problem
    Thank you
    Regards
    Farukh

    find the library d2kwutil.pll (probably in c:\orawin95\tools\devdem60\demo\forms) and copy it and d2kwut32.dll to your application directory. Attach the pll to your form; now you can "interface" with windows. So for pausing you application use this in you form:
    win_api_utility.sleep(1000);
    the parameter takes milliseconds. so in the example it's 1000 milliseconds or 1 second.
    good luck!
    Tim

  • "A critical error has occurred while running the virtual machine and the machine execution has been stopped"

    I have the following error:
    "A critical error has occurred while running the virtual machine and the machine execution has been stopped"
    When I am installing grid clusterware and when is copying files from one node to other I received that virtualbox error and is stop working.
    Can somebody give me any hint how to solve it ?
    Thank you
    Eugen

    I think that is not a Clusterware issue, The clusterware installation may generating a high load on your machine and Virtual Box is not supporting.
    Check vbox.log file to identify root cause.

Maybe you are looking for

  • Description of key figure for multi language support issue.

    Hi Experts, Have a good day ahead!! Custom key figure description multi for the language support issue The key figure is created in English  language and description also in English. When I have logged in to English language and checked the report in

  • Chimes on wake up

    I just installed a new Thunderbolt display to go along with my rMBP. Now, when the monitor (either the Thunderbolt or retina) turns off after a period of non-use, the Mac makes a chime sound (same as new mail arriving in Outlook) at least once but us

  • /sapapo/vs01- Adding a feild to Output Dispaly

    Hi, I have appended a field to the displaying structure:/SAPAPO/VSR_G_FUNIT,which displays the orders. I tried to change the filed catalog for that structure by deleting the indicator for NO_OUT = space & TECH = X, i made same as all other fields pro

  • How to "deauthorize all computers" in iTunes?

    A computer has died I am attempting to deauthorize all computers in iTunes in order to remove it from the authorized computer list.  However, none of the other "authorized" computers display the "Deauthorize All Computers" option on the "Store" menu

  • Prerequisites for 1Z0-047 (Certified SQL Expert)?

    I know a lot of the Oracle certification paths require that you take Oracle-sponsored training. the 1Z0-047 one however lists "recommended" training. I can't find anywhere that says whether the training is explicitly required, or whether it's accepta