There are two Java files. One is A, and the other is B. Both A and B have main functions. Then I run A, and in A, I start a Process of B through ProcessBuilder.start().
I can debug the code of A. However, I cannot debug B. Even when I add breakpoint in B's main function, Eclipse does not stop at that line of B. So far the only method that I can think of is to simulate the parameters in A, and call B's main function directly. But it's not quite convenient. Is there any simple & direct way?
Thanks in advance for any suggestions.
Don't start a different process using the process builder; if you need A and B's main
methods to run concurrently, you can use Threads.
public class A {
public static void main(String[] args) {
Thread bThread = new Thread(new Runnable() {
public void run() {
B.main(args);
}
});
bThread.start();
// Doing something for A
}
}
public class B {
public static void main(String[] args) {
// Doing something for B
}
}
Starting separate processes for Java is generally a bad idea as you can run everything in the same process. There are limited use-cases where it is still applicable but since you haven't provided a rationale for starting a process, I think you didn't know about being able to use Threads.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.