Last active
August 27, 2018 16:20
-
-
Save Kiarahmani/2a49a0c0a512c99bfd65c69cce257aab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
//////////////////// CREATING THE IGNITE CACHE INSTANCE | |
public void createAllCaches(Ignite ignite) { | |
// INITILIZE A SER CACHE: | |
CacheConfiguration<Integer, Integer> counter_cache = new CacheConfiguration<Integer, Integer>("counter"); | |
counter_cache.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); | |
counter_cache.setCacheMode(CacheMode.REPLICATED); | |
ignite.createCache(counter_cache); | |
} | |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
///////////////////2 THE CONCURRENT TASK OF INCEREMENTING A COUNTER | |
task = new Runnable() { | |
@Override | |
public void run() { | |
try (Transaction tx = transactions.txStart(_PESS, _SER)) { | |
int value = counter_cache.get(1); | |
counter_cache.put(1,value+1) | |
} | |
} | |
}; | |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
////////////////////3 DISPATCHING & WAITING FOR THE CONCURRENT CLIENTS | |
public void startAll(Caches caches) { | |
this.caches = caches; // the object containing an ignite cache instance | |
// INITIATE CONCURRENT CLIENTS Using the same cache | |
clientsStartTime = System.currentTimeMillis(); | |
threads = new Thread[_CLIENT_NUMBER]; // dispatching concurrent clients | |
for (int i = 0; i < _CLIENT_NUMBER; i++) { | |
threads[i] = new Thread(task); // The runnable function which increments a simple counter by 1 | |
threads[i].start(); | |
} | |
} | |
public void joinAll(Constants cons) { | |
for (int i = 0; i < cons._CLIENT_NUMBER; i++) { | |
try { | |
threads[i].join(); | |
} catch (InterruptedException e) { | |
System.out.println(e); | |
} | |
} | |
clientsFinishTime = System.currentTimeMillis(); | |
} | |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment