Search in sources :

Example 1 with ConcurrentHashMapPro

use of lucee.commons.collection.concurrent.ConcurrentHashMapPro in project Lucee by lucee.

the class HashMapPro method main.

public static void main(String[] args) {
    // HashMapPro<Key, Object> map=new HashMapPro<Key, Object>();
    long startx = System.currentTimeMillis();
    for (int i = 0; i < 10000000; i++) {
        KeyImpl.init("K" + i);
    }
    aprint.e("init.key:" + (System.currentTimeMillis() - startx));
    HashMapPro<Key, Object> map = new HashMapPro<Key, Object>();
    Map<Key, Object> sm = Collections.synchronizedMap(map);
    ConcurrentHashMapPro<Key, Object> map2 = new ConcurrentHashMapPro<Key, Object>();
    HashMap<Key, Object> hm = new HashMap<Key, Object>();
    Key[] keys = new Key[100];
    for (int i = 0; i < 100; i++) {
        keys[i] = KeyImpl.init("K" + i);
        map.put(keys[i], "" + i);
        map2.put(keys[i], "" + i);
        hm.put(keys[i], "" + i);
    }
    for (int i = 0; i < 100; i++) {
        keys[i] = KeyImpl.init("K" + i);
    }
    long start = System.currentTimeMillis();
    for (int i = 0; i < 100000000; i++) {
        // map.g(keys[37],null);
        map.get(keys[37]);
    // k.hashCode();
    }
    aprint.e("HM.get:" + (System.currentTimeMillis() - start));
    start = System.currentTimeMillis();
    for (int i = 0; i < 100000000; i++) {
        map.g(keys[37], null);
    // map.get(keys[37]);
    // k.hashCode();
    }
    aprint.e("HM.g:" + (System.currentTimeMillis() - start));
    start = System.currentTimeMillis();
    for (int i = 0; i < 100000000; i++) {
        // map.g(keys[37],null);
        map.get(keys[37]);
    // k.hashCode();
    }
    aprint.e("HM.get:" + (System.currentTimeMillis() - start));
    start = System.currentTimeMillis();
    for (int i = 0; i < 100000000; i++) {
        // map.g(keys[37],null);
        map.put(keys[37], "");
    // map.get(keys[37]);
    // k.hashCode();
    }
    aprint.e("HM.put:" + (System.currentTimeMillis() - start));
    // ///////////////////////////////////////
    start = System.currentTimeMillis();
    for (int i = 0; i < 100000000; i++) {
        // map.g(keys[37],null);
        map2.get(keys[37]);
    // k.hashCode();
    }
    aprint.e("CHM.get:" + (System.currentTimeMillis() - start));
    start = System.currentTimeMillis();
    for (int i = 0; i < 100000000; i++) {
        map2.g(keys[37], null);
    // map.get(keys[37]);
    // k.hashCode();
    }
    aprint.e("CHM.g:" + (System.currentTimeMillis() - start));
    start = System.currentTimeMillis();
    for (int i = 0; i < 100000000; i++) {
        // map.g(keys[37],null);
        map2.get(keys[37]);
    // k.hashCode();
    }
    aprint.e("CHM.get:" + (System.currentTimeMillis() - start));
    start = System.currentTimeMillis();
    for (int i = 0; i < 100000000; i++) {
        // map2.g(keys[37],null);
        map2.put(keys[37], "");
    // map.get(keys[37]);
    // k.hashCode();
    }
    aprint.e("CHM.put:" + (System.currentTimeMillis() - start));
    // ///////////////////////////////////////
    start = System.currentTimeMillis();
    for (int i = 0; i < 100000000; i++) {
        // map.g(keys[37],null);
        sm.get(keys[37]);
    // k.hashCode();
    }
    aprint.e("SM.get:" + (System.currentTimeMillis() - start));
    start = System.currentTimeMillis();
    for (int i = 0; i < 100000000; i++) {
        // map2.g(keys[37],null);
        sm.put(keys[37], "");
    // map.get(keys[37]);
    // k.hashCode();
    }
    aprint.e("SM.put:" + (System.currentTimeMillis() - start));
    // ///////////////////////////////////////
    start = System.currentTimeMillis();
    for (int i = 0; i < 100000000; i++) {
        // map.g(keys[37],null);
        hm.get(keys[37]);
    // k.hashCode();
    }
    aprint.e("SM.get:" + (System.currentTimeMillis() - start));
    start = System.currentTimeMillis();
    for (int i = 0; i < 100000000; i++) {
        // map2.g(keys[37],null);
        hm.put(keys[37], "");
    // map.get(keys[37]);
    // k.hashCode();
    }
    aprint.e("SM.put:" + (System.currentTimeMillis() - start));
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMapPro(lucee.commons.collection.concurrent.ConcurrentHashMapPro) ConcurrentHashMapPro(lucee.commons.collection.concurrent.ConcurrentHashMapPro) lucee.aprint(lucee.aprint) Key(lucee.runtime.type.Collection.Key)

Example 2 with ConcurrentHashMapPro

use of lucee.commons.collection.concurrent.ConcurrentHashMapPro in project Lucee by lucee.

the class IKStorageScopeSupport method getInstance.

public static Scope getInstance(int scope, IKHandler handler, String appName, String name, PageContext pc, Scope existing, Log log) throws PageException {
    IKStorageValue sv = null;
    if (Scope.SCOPE_SESSION == scope)
        sv = handler.loadData(pc, appName, name, "session", Scope.SCOPE_SESSION, log);
    else if (Scope.SCOPE_CLIENT == scope)
        sv = handler.loadData(pc, appName, name, "client", Scope.SCOPE_CLIENT, log);
    if (sv != null) {
        long time = sv.lastModified();
        if (existing instanceof IKStorageScopeSupport) {
            IKStorageScopeSupport tmp = ((IKStorageScopeSupport) existing);
            if (tmp.lastModified() >= time && name.equalsIgnoreCase(tmp.getStorage())) {
                return existing;
            }
        }
        if (Scope.SCOPE_SESSION == scope)
            return new IKStorageScopeSession(pc, handler, appName, name, sv.getValue(), time);
        else if (Scope.SCOPE_CLIENT == scope)
            return new IKStorageScopeClient(pc, handler, appName, name, sv.getValue(), time);
    } else if (existing instanceof IKStorageScopeSupport) {
        IKStorageScopeSupport tmp = ((IKStorageScopeSupport) existing);
        if (name.equalsIgnoreCase(tmp.getStorage())) {
            return existing;
        }
    }
    IKStorageScopeSupport rtn = null;
    ConcurrentHashMapPro<Key, IKStorageScopeItem> map = new ConcurrentHashMapPro<Collection.Key, IKStorageScopeItem>();
    if (Scope.SCOPE_SESSION == scope)
        rtn = new IKStorageScopeSession(pc, handler, appName, name, map, 0);
    else if (Scope.SCOPE_CLIENT == scope)
        rtn = new IKStorageScopeClient(pc, handler, appName, name, map, 0);
    rtn.store(pc);
    return rtn;
}
Also used : IKStorageScopeSession(lucee.runtime.type.scope.session.IKStorageScopeSession) Collection(lucee.runtime.type.Collection) IKStorageScopeClient(lucee.runtime.type.scope.client.IKStorageScopeClient) ConcurrentHashMapPro(lucee.commons.collection.concurrent.ConcurrentHashMapPro)

Example 3 with ConcurrentHashMapPro

use of lucee.commons.collection.concurrent.ConcurrentHashMapPro in project Lucee by lucee.

the class IKStorageScopeSupport method touchBeforeRequest.

@Override
public void touchBeforeRequest(PageContext pc) {
    hasChanges = false;
    setTimeSpan(pc);
    // lastvisit=System.currentTimeMillis();
    if (data == null)
        data = new ConcurrentHashMapPro<Collection.Key, IKStorageScopeItem>();
    data.put(KeyConstants._cfid, new IKStorageScopeItem(pc.getCFID()));
    data.put(KeyConstants._cftoken, new IKStorageScopeItem(pc.getCFToken()));
    data.put(URLTOKEN, new IKStorageScopeItem(pc.getURLToken()));
    data.put(LASTVISIT, new IKStorageScopeItem(_lastvisit));
    _lastvisit = new DateTimeImpl(pc.getConfig());
    lastvisit = System.currentTimeMillis();
    if (type == SCOPE_CLIENT) {
        data.put(HITCOUNT, new IKStorageScopeItem(new Double(hitcount++)));
    } else {
        data.put(SESSION_ID, new IKStorageScopeItem(pc.getApplicationContext().getName() + "_" + pc.getCFID() + "_" + pc.getCFToken()));
    }
    data.put(TIMECREATED, new IKStorageScopeItem(timecreated));
}
Also used : Collection(lucee.runtime.type.Collection) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) ConcurrentHashMapPro(lucee.commons.collection.concurrent.ConcurrentHashMapPro)

Aggregations

ConcurrentHashMapPro (lucee.commons.collection.concurrent.ConcurrentHashMapPro)3 Collection (lucee.runtime.type.Collection)2 HashMap (java.util.HashMap)1 lucee.aprint (lucee.aprint)1 Key (lucee.runtime.type.Collection.Key)1 DateTimeImpl (lucee.runtime.type.dt.DateTimeImpl)1 IKStorageScopeClient (lucee.runtime.type.scope.client.IKStorageScopeClient)1 IKStorageScopeSession (lucee.runtime.type.scope.session.IKStorageScopeSession)1