Java Code Examples for org.apache.uima.jcas.cas.TOP#_createSearchKey

The following examples show how to use org.apache.uima.jcas.cas.TOP#_createSearchKey . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JCasHashMapCompareTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
private int runConCur(int numberOfThreads) throws Exception {
    final ConcurrentMap<Integer, TOP> m =
        new ConcurrentHashMap<>(200, 0.75F, numberOfThreads);
    concurrentMap = m;
    
    final int numberOfWaiters = numberOfThreads*2;
    final Object[] waiters = new Object[numberOfWaiters];
    for (int i = 0; i < numberOfWaiters; i++) {
      waiters[i] = new Object();
    }
    MultiThreadUtils.Run2isb run2isb= new MultiThreadUtils.Run2isb() {
      
      public void call(int threadNumber, int repeatNumber, StringBuilder sb) {
//        int founds = 0, puts = 0;
        for (int i = 0; i < sizeOfTest*threadNumber; i++) {
          final int key = hash(i, threadNumber) / 2;
          final Object waiter = waiters[key & (numberOfWaiters - 1)];
          TOP newFs = TOP._createSearchKey(key);
          TOP fs = m.putIfAbsent(key, newFs);
//          while (fs != null && fs._isJCasHashMapReserve()) {
//            // someone else reserved this
//
//            // wait for notify
//            synchronized (waiter) {
//              fs = m.get(key);
//              if (fs._isJCasHashMapReserve()) {
//                try {
//                  waiter.wait();
//                } catch (InterruptedException e) {
//                }
//              }
//            }
//          }
//            
////          TOP fs = m.get(key);
//          if (null == fs) {
////            puts ++;
//            TOP prev = m.put(key,  TOP._createSearchKey(key));
//            if (prev._isJCasHashMapReserve()) {
//              synchronized (waiter) {
//                waiter.notifyAll();
//              }
//            }
////              puts --;  // someone beat us 
////              founds ++;
//          }
//          
        } // end of for loop
////        System.out.println("concur Puts = " + puts + ", founds = " + founds);
      }  
    };  
    long start = System.currentTimeMillis();
    MultiThreadUtils.tstMultiThread("JCasHashMapTestCompConcur",  numberOfThreads, 10, run2isb,
        new Runnable() {
          public void run() {
            m.clear();
        }});
    System.out.format("JCasCompTest - using ConcurrentHashMap, threads = %d, time = %,f seconds%n", numberOfThreads, ((double)(System.currentTimeMillis() - start)) / 1000.d);
    return m.size();
  }