i have written a Runnable class
private static class Processing implements Runnable {
private static File file;
private static byte[] message;
public Processing ( File f, byte[] m ){
this.file = f;
this.message = m;
}
public void run(){
WriteToFile( file , message );
... other processing....
}
private static void WriteToFile( File f , byte[] msg ){
FileOutputStream fs = null;
try {
fs = new FileOutputStream( f ) ;
fs.write( msg );
fs.flush();
fs.close();
}catch (Exception e){
e.printStackTrace();
}
}
In the main class
public class MainClass{
public void somemethod(){
....
( new Thread(new Processing ( <somefile> , <somebytes> ))).start();
....
}
}
My question is
- is this method correct? my wish is to improve file io (in the WriteToFile method) because MainClass is called by more than 1000 users.
How can I simulate 1000 users in the code? is it
for (int i = 0 ; i<1000 ...){ ( new Thread(new Processing ( <somefile> , <somebytes> ))).start(); }
thanks