Advertisement
danpalol

Untitled

Nov 6th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. public class EffInit extends Thread{
  2.  
  3. private int start;
  4. private int dim;
  5. public static int[] data;
  6. public static final int SIZE = 100000000;
  7. public static final int MAX_THR = 8;
  8.  
  9. public EffInit (int start, int dim){
  10. this.start=start;
  11. this.dim=dim;
  12. }
  13.  
  14. public static void main(String[] args) {
  15. data = new int [SIZE];
  16. long begin, end;
  17. int start,j;
  18. EffInit[] threads;
  19.  
  20. for(int numThread=1;numThread<=MAX_THR;numThread++){
  21. begin= System.currentTimeMillis();
  22. start=0;
  23. threads= new EffInit[numThread];
  24. for(j=0;j<numThread;j++){
  25. threads[j] = new EffInit(start,SIZE/numThread);
  26. threads[j].start();
  27. start+= SIZE/numThread;
  28. }
  29. for(j=0;j<numThread;j++){
  30. try{
  31. threads[j].join();
  32. } catch(InterruptedException e) {
  33. e.printStackTrace();
  34.  
  35. }
  36. }
  37. end=System.currentTimeMillis();
  38. System.out.println(numThread+" Thread(s) :"+ (end-begin)+ "ms");
  39.  
  40. }
  41. }
  42.  
  43. public void run(){
  44. int j;
  45. for(int i=0;i<this.dim;i++){
  46. for(j=0;j<10000;j++){
  47. data[this.start + i]=i;
  48. }
  49. }
  50.  
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement