第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

關(guān)于java 泛型設(shè)計(jì)接口 導(dǎo)致的參數(shù)類型不匹配問題

關(guān)于java 泛型設(shè)計(jì)接口 導(dǎo)致的參數(shù)類型不匹配問題

紅顏莎娜 2019-03-01 11:03:28
1.設(shè)計(jì)了一個(gè)接口用于包裝其它 pojo,以計(jì)算是否過期 public interface CatchWrapper<T>{ public long getCatchedTime(); public T getValue(); public boolean valid(); } 某一個(gè)實(shí)現(xiàn): public class DeviceCatchWrapper implements CatchWrapper<Device> { private final long catchedTime; private final Device device; private static final long CATCH_TIME = 20*1000; public DeviceCatchWrapper(Device device) { this.device = device; catchedTime = System.currentTimeMillis(); } @Override public long getCatchedTime() { return catchedTime; } @Override public Device getValue() { return device; } @Override public boolean valid() { return System.currentTimeMillis() - catchedTime < CATCH_TIME; } } 另有一個(gè)管理類,主要是刪除過期的緩存 public class DeviceCatchWrapperManager<T> { private static final ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); private final ConcurrentMap<String, CatchWrapper<T>> catchStore; private final long initialDelay; private final long delay; private TimeUnit unit; private volatile boolean stop = false; public DeviceCatchWrapperManager(ConcurrentMap<String,CatchWrapper<T>> catchStore, long initialDelay, long delay, TimeUnit unit) { this.catchStore = catchStore; this.initialDelay = initialDelay; this.delay = delay; this.unit = unit; } /** * 周期性檢查過期的緩存,然后刪除 */ public void startLoop() { service.scheduleWithFixedDelay(new Runnable() { @Override public void run() { for (Entry<String, CatchWrapper<T>> entry : catchStore.entrySet()) { if (stop) break; String key = entry.getKey(); CatchWrapper<T> cw = entry.getValue(); if (!cw.valid()){ System.out.println("Device catch manager --------------->remove:"+key); catchStore.remove(key, cw); } } } }, initialDelay, delay, unit); } /** * 停在對緩存進(jìn)行過期檢查 */ public void stop() { stop = true; service.shutdownNow(); } } 但是真正構(gòu)造函數(shù) 傳參數(shù)報(bào)錯(cuò) private final ConcurrentMap<String, DeviceCatchWrapper> catchMap = new ConcurrentHashMap<>(); 下面的報(bào)錯(cuò),參數(shù)不對 private final DeviceCatchWrapperManager<Device> catchManager = new DeviceCatchWrapperManager<Device>(catchMap, 2, 2, TimeUnit.HOURS); 改怎么解決這個(gè)錯(cuò)誤 或者 該怎么設(shè)計(jì)接口或者改進(jìn)呢?
查看完整描述

1 回答

?
胡子哥哥

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊

ConcurrentMap<String, DeviceCatchWrapper> catchMap = new ConcurrentHashMap<>(); 這句有問題
改成ConcurrentMap<String, CatchWrapper<Device>> catchMap = new ConcurrentHashMap<String, DeviceCatchWrapper>();試試

查看完整回答
反對 回復(fù) 2019-03-01
  • 1 回答
  • 0 關(guān)注
  • 940 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號