I am testing my server application that receives Job objects and for this I have created a dummy client that sends my Server application as much amount of Job Objects as possible and for this I have created a Timer class as given below that sends Job objects to the server on constant basis. e.g. 2000 objects every second. But my client becomes slow when i exceed 2000 jobs per second.
Is there any other way to send large and fixed amount of jobs to the server?
If i create many Timer Instances then i have to synchronize the Socket which again makes things slow.
Is there any better solution to this problem with the help of which I can send thousands of job to the server without making things slow?
The code given here is a skeleton of Job etc and I just want to know other alternatives.
package comeOn;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import java.io.*;
import java.awt.event.ActionEvent;
public class LoadGenerator extends Timer implements ActionListener{
ObjectOutputStream outStream=null;
int rndNumber;
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public LoadGenerator(int interval, ObjectOutputStream outStream,int rndNumber){
super(interval,null);
this.outStream=outStream;
this.rndNumber=rndNumber;
addActionListener(this);
//this.setInitialDelay(1000);//start this timer afer 1 second.
}
@Override
public void actionPerformed(ActionEvent e){
try {
for(int i=1;i<=rndNumber;i++){
Job job=new Job(100);
outStream.writeObject(job);
outStream.reset();
outStream.flush();
}
}
catch(Exception ex){}
}
class Job{
int amount;
Job(int amount){
this.amount=amount;
}
}
}