Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. import java.util.concurrent.ConcurrentHashMap;
  2.  
  3. import org.apache.commons.lang.RandomStringUtils;
  4.  
  5. public class UpdateHashMap implements Runnable {
  6.  
  7. protected int objectCount;
  8. protected static ConcurrentHashMap<String, String> map = null;
  9. protected String threadName = "";
  10. protected String seed = "";
  11. String[] Objects = null;
  12.  
  13. public static ConcurrentHashMap<String, String> getMap()
  14. {
  15. if(map == null)
  16. {
  17. map = new ConcurrentHashMap<String, String>();
  18. }
  19. return map;
  20. }
  21.  
  22. public UpdateHashMap( String threadName, int objectCount, String seed, String[] Objects) {
  23. this.threadName = threadName;
  24. this.objectCount = objectCount;
  25. this.seed = seed;
  26. this.Objects = Objects;
  27. }
  28.  
  29. public void run() {
  30.  
  31. long t1 = System.currentTimeMillis();
  32.  
  33. try {
  34. for (int i = 0; i < this.objectCount; i++) {
  35. String objectSeed = seed + ":Object-" + i;
  36. getMap().put(objectSeed, Objects[i]);
  37. }
  38. } catch (Throwable t) {
  39. t.printStackTrace();
  40. }
  41.  
  42. System.out.println(threadName + " " + (System.currentTimeMillis() - t1));
  43. }
  44.  
  45. public static void main(String[] args) {
  46.  
  47. if (args.length != 4) {
  48. System.out.println("Usage: ");
  49. System.out.println("java -Xbootclasspath/p:<path-to-bootjar>");
  50. System.out.println(" -Dtc.config=<path-to-tc-config>");
  51. System.out.println(" -Dtc.install-root=<path-to-trct-installation>");
  52. System.out.println(" -classpath commons-lang-2.4.jar:.");
  53. System.out.println(" UpdateHashMap <ObjectCount> <ThreadCount> <Seed> <ObjectSizeinKB>");
  54. System.exit(0);
  55. }
  56.  
  57. int objectCount = Integer.parseInt(args[0]);
  58. int threadCount = Integer.parseInt(args[1]);
  59. String seed = args[2];
  60. int objectSizeInKb = Integer.parseInt(args[3]);
  61.  
  62. Thread thread[] = new Thread[threadCount];
  63.  
  64. for (int i = 0; i < threadCount; i++) {
  65. String[] Objects = new String[objectCount];
  66. for (int temp1 = 0; temp1 < objectCount; temp1++) {
  67. Objects[temp1] = RandomStringUtils.randomAlphanumeric(objectSizeInKb * 1024);
  68. }
  69.  
  70. thread[i] = new Thread(new UpdateHashMap( "Thread-" + i, objectCount, seed
  71. + ":Thread-" + i, Objects));
  72. }
  73.  
  74. for (int i = 0; i < threadCount; i++) {
  75. thread[i].start();
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement