Skip to content

Instantly share code, notes, and snippets.

@jackeylu
Created July 1, 2016 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackeylu/91f8722cf7cba83a44721bcdb041ea05 to your computer and use it in GitHub Desktop.
Save jackeylu/91f8722cf7cba83a44721bcdb041ea05 to your computer and use it in GitHub Desktop.
Cache Operations, currently only with putting.
public class CacheOperations {
public void putOperations(Ignite ignite, String cache_name, int thread_num) {
TimeRecord tr = new TimeRecord();
tr.reset();
int step = 20000;
PutTask[] tasks = new PutTask[thread_num];
for (int i = 0; i < thread_num; i++) {
tasks[i] = new PutTask(ignite, cache_name, step*(i-1), step*i);
tasks[i].start();
}
for (PutTask task: tasks){
try {
task.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
long cost = tr.end();
System.out.println(Format.ops(thread_num*step, cost));
}
private class PutTask extends Thread{
private IgniteCache cache;
private int begin;
private int end;
public PutTask(Ignite ignite, String cache_name, int begin, int end){
this.cache = ignite.getOrCreateCache(cache_name);
this.begin = begin;
this.end = end;
}
@Override
public void run() {
for (int i = begin; i < end; i++){
cache.put(i, i);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment