Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help Beginner  RSS feed

 
J. Alenis
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I would like to run x times the same job to test the system performance so multiple jobs run at the same time.

Can anyone help me, I'm just a beginner.

Thx
 
Sandeep Jindal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hye J.

Why do u need threads to run a same job x times??

You can do it in a simple way something like this:



This looks very simple



Regards
Sandeep
 
Van Glass
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to run the jobs simultaneously you would want the Job class to extend the Thread class or implement Runnable class. The work of the job would be in the public void run method.

Example

public class Job extends Thread {
public void run() {
// place work here
}
}

Then you could run a loop which starts up all those jobs to run at once

class JobRunner{

public static void main(String argument[]){

int x= 1000;

for(int i=0; i<x; i++){

Job job = new Job();
job.start();

}

}

}
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!