Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8083671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:32:56+00:00 2026-06-05T17:32:56+00:00

I have a program with 2 process java : processA and processB ( 2

  • 0

I have a program with 2 process java : processA and processB ( 2 process java.exe not 2 threads).
i use code block below from process A to invoke processB this code is wrapped in RunTask class below

public class RunTask implements Callable<Object> {

private String runParams;

public String getRunParams() {
    return runParams;
}

public void setRunParams(String runParams) {
    this.runParams = runParams;
}

@Override
public Object call() throws Exception {
    try {
        //System.out.println("run:" + runParams);
        Process procB = Runtime.getRuntime().exec("java -jar processB.jar);
        DataInputStream ls_in = new DataInputStream(procB.getInputStream());
        String ls_str;
        while ((ls_str = ls_in.readLine()) != null) {
            System.out.println(ls_str);
        }

    } catch (Exception exp) {
        exp.printStackTrace();
    }
    return null;
}
}

and Main class i use executor

   ExecutorService eservice = Executors.newSingleThreadExecutor();
        while (1 == 1) {
            String stringParams = getFilesNeedToImportAsString();
            if (stringParams.trim().isEmpty()) {
                long l1 = System.currentTimeMillis() - l;
                System.out.println("all time" + l1 / 1000);
                System.exit(100);
            }
            RunTask runTask = new RunTask();
            runTask.setRunParams(SystemInfo.RUN_COMMAND + stringParams);
            Future<Object> objectFuture = eservice.submit(runTask);
            while (!objectFuture.isDone()) {
                System.out.println("waiting the task running");
                Thread.sleep(500);
            }
        }

But when an exception occurred on processB both processes (processA,processB) seem be halted this is code run on processB

public Object call() {
    try {
        MutationResult result = mutator.execute();
        return "ok";
    } catch (Exception exp) {
        exp.printStackTrace();
        System.out.println("error on " + Thread.currentThread().getName() + "failed begin retry " + (++retryCount));
        call();
        System.out.println(retryCount + " completed");
        return "ok";
    }

}

if i run processB stand alone (by command line) it’s never happen, or when this problem occured i use taskmanager to kill proceesA (callee), processB continue to run

Please any one give me the solution for this problem !!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:32:59+00:00Added an answer on June 5, 2026 at 5:32 pm

    You wait on objectFuture isDone method to complete. According to the documentation:

    isDone: Returns true if this task completed. Completion may be due to
    normal termination, an exception, or cancellation — in all of these
    cases, this method will return true

    Looking at the code in processB when an exception occurs you execute call() again recursively. I understand that you do this as a error retry mechanism but this is a really bad idea for two main reasons:
    – If the exception persists you will end up getting a StackOverflowException.
    – None of the conditions for isDone will be met.

    A better alternative will be defining a maximum number of retries and try executing mutator.execute(). If the error persists then throw and exception and finish execution.

    Another option would be to wait to processB to finish for a maximum time after which you cancel the execution of the task by calling objectFuture.cancel(true).

    A couple of comments on processA: On RunTask you don’t use runParams which seem to be some files that need to be imported as string. Also, you use readLine() on DataInputStream which is a deprecated method. Instead use an InputStream (e.g. BufferedInputStream) wrapped in an InputStreamReader and then wrapped in a BufferedReader – then call readLine() on the BufferedReader.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below code to run a java program from a file. import
I have a program which needs to invoke a process to perform an operation
I have the next code: Process p = Runtime.getRuntime().exec(args); and I want my program
Can a Java.exe JVM restart itself somehow? If you have a Java program running
I'm having two files that I've to invoke from a java program: a batch
I want to execute a external .exe program from within java. The .exe is
I have a Java program which is being started via ProcessBuilder from another Java
I'm starting a Process from a Java program. I hold onto it and at
I have a debugging program which I've written to attach to a process and
I have 2 processes in my Win32 console application. 1 process - main program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.