简体   繁体   中英

How to run two instances of the same java program in parallel?

I have a java program which uses HttpUrlConnection to make POST calls. What I want to do now is to see if there are 2-3 parallel calls making the same changes, then what happens. Is each call able to make the rewuired changes, and if not then which call is given precedence. To debug for this, I need to run parallel instances of the same java program in eclipse. How can this be done? I don't want to use threads, a totally independent execution of the same program.

Compile the source and run the program from command line.

We want to separate the source from the generated files, so our java source files will be in src folder. All generated files should be under build, and there splitted into several subdirectories for the individual steps: classes for our compiled files and jar for our own JAR-file.

We have to create only the src directory. (Because I am working on Windows, here is the win-syntax - translate to your shell):

md src

The following simple Java class just prints a fixed message out to STDOUT, so just write this code into src\\oata\\HelloWorld.java .

package oata;

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

Now just try to compile and run that:

md build\classes
javac -sourcepath src -d build\classes src\oata\HelloWorld.java
java -cp build\classes oata.HelloWorld

Read more here .

You can also build into a jar and create a script to multiple execute the program.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM