Scheduling multiple instance of a single java process

433 views Asked by At

We have a Java process, which we want to perform load testing on. This process makes a REST call to an external vendor. We want to monitor the performance over the weekend. It should be tested with around 1000 instances of the process running. What are the possible ways to do it?

I have 2 solutions:

  1. Starting the process in multiple terminals, however given that we want to do this for 1000 instance is not practical.

  2. Write a shell script to instantiate this, to clone.

Is there any better solution to this?

Any library would be helpful.

Below is the sample code that we want to schedule:

 public static void main(String[] args) {


    try {
        getToken();
        Thread.sleep(10000);
    } catch (Exception e) {

        e.printStackTrace();
    }


    final Timer timer = new Timer();
    Timer stopTaskTimer = new Timer();
    TimerTask task = new TimerTask() {
        @Override
        public void run() {
            try {
                /*getToken();

                Thread.sleep(15000);*/
                getResponse("#############");


            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    TimerTask stopTask = new TimerTask() {
        @Override
        public void run() {
            timer.cancel();

        }
    };

    timer.scheduleAtFixedRate(task, 0, 60000);
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = sdf.parse("2015-06-20 19:41:30");
        //stopTaskTimer.schedule(stopTask, date);
    } catch (ParseException e) {
        e.printStackTrace();
    }

}
2

There are 2 answers

0
Audrius Meškauskas On

Use JMeter or other comparable load testing tool. It supports all you require out of box.

0
Samuel Åslund On

@h22 probably have the better solution but to answer your question:

Move the code from main into a "run" method and make your class implement "runnable" then make a loop in the "main" that starts the required amount of java.lang.Thread https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html