Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.concurrent.ConcurrentHashMap;
- import org.apache.commons.lang.RandomStringUtils;
- public class UpdateHashMap implements Runnable {
- protected int objectCount;
- protected static ConcurrentHashMap<String, String> map = null;
- protected String threadName = "";
- protected String seed = "";
- String[] Objects = null;
- public static ConcurrentHashMap<String, String> getMap()
- {
- if(map == null)
- {
- map = new ConcurrentHashMap<String, String>();
- }
- return map;
- }
- public UpdateHashMap( String threadName, int objectCount, String seed, String[] Objects) {
- this.threadName = threadName;
- this.objectCount = objectCount;
- this.seed = seed;
- this.Objects = Objects;
- }
- public void run() {
- long t1 = System.currentTimeMillis();
- try {
- for (int i = 0; i < this.objectCount; i++) {
- String objectSeed = seed + ":Object-" + i;
- getMap().put(objectSeed, Objects[i]);
- }
- } catch (Throwable t) {
- t.printStackTrace();
- }
- System.out.println(threadName + " " + (System.currentTimeMillis() - t1));
- }
- public static void main(String[] args) {
- if (args.length != 4) {
- System.out.println("Usage: ");
- System.out.println("java -Xbootclasspath/p:<path-to-bootjar>");
- System.out.println(" -Dtc.config=<path-to-tc-config>");
- System.out.println(" -Dtc.install-root=<path-to-trct-installation>");
- System.out.println(" -classpath commons-lang-2.4.jar:.");
- System.out.println(" UpdateHashMap <ObjectCount> <ThreadCount> <Seed> <ObjectSizeinKB>");
- System.exit(0);
- }
- int objectCount = Integer.parseInt(args[0]);
- int threadCount = Integer.parseInt(args[1]);
- String seed = args[2];
- int objectSizeInKb = Integer.parseInt(args[3]);
- Thread thread[] = new Thread[threadCount];
- for (int i = 0; i < threadCount; i++) {
- String[] Objects = new String[objectCount];
- for (int temp1 = 0; temp1 < objectCount; temp1++) {
- Objects[temp1] = RandomStringUtils.randomAlphanumeric(objectSizeInKb * 1024);
- }
- thread[i] = new Thread(new UpdateHashMap( "Thread-" + i, objectCount, seed
- + ":Thread-" + i, Objects));
- }
- for (int i = 0; i < threadCount; i++) {
- thread[i].start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement