我有一个智能卡读卡器池,我可以使用它们来计算数字签名。 这个智能卡需要一段时间才能签名,所以我需要设置一个池来排队请求并尽快处理它们。
这就是我使用单个智能卡的方式:
try{
Smartcard smartcard=new Smartcard(slot); //slot: reader number
smartcard.sign(file);
}catch(SmartcardException e){
throw e; //unusable smartcard
}
我想使用ExcecutorService来管理多个智能卡,使用的池大小等于智能卡读卡器。 我怀疑的是,如果使用这个对象,我可以将一个读取器附加到每个线程,而且,如果它可以阻止单个线程,以防其智能卡因SmartcardException而失败(例如:智能卡被移除或损坏)。
我恢复:
ExcecutorService适合吗?
答案 0 :(得分:1)
ExecutorService使用BlockingQueue
备份提交。这些队列显然是FIFO,因此默认情况下,线程池将尽快为每个请求执行。