上图是我的数据结构。我定义了一个线程安全的静态变量(作用:消息队列)用来存储消息,如下:
private static ConcurrentDictionary<string, ConcurrentQueue<SignalModel>> _dic = new ConcurrentDictionary<string, ConcurrentQueue<SignalModel>>();
既用到了ConcurrentDictionary又用到了ConcurrentQueue。用字典是因为要根据IP分组存储。
我就是不知道用了ConcurrentDictionary之后,字典的value是否还有必要使用ConcurrentQueue来定义。
是否应该将ConcurrentQueue改成List?
参考 Concurrent collections is it safe to modify from different threads:
ConcurrentQueue is only ensuring that calls to methods of that class are observed to be atomic; it is making no other guarantees surrounding thread safety.
根据你发的引用文字和上面的截图,我得出结论,就是还得用ConcurrentDictionary<string, ConcurrentQueue<SignalModel>>类型来定义。是这样的吗?
@屌丝大叔的笔记: 要根据你的应用场景
@dudu: 是的,很符合,谢谢!