简体   繁体   中英

ExecutorService control thread pools

I have a pool of smartcards reader and I can use them to compute a digital signature. This smartcard take a while to sign, so I need to setup a pool to queue requests and handle them as soon as possibile.

This is how I use a single smartcards:

try{
   Smartcard smartcard=new Smartcard(slot); //slot: reader number
   smartcard.sign(file);
}catch(SmartcardException e){
   throw e; //unusable smartcard
}

I thought to use ExcecutorService to manage multiple smartcards using a pool size equals to smartcard readers. My doubt is if with this object I can attach a single reader to each thread, and moreover, if it can stop a single thread in case its smartcard fails with an SmartcardException (example: smartcard removed or broken).

I resume:

  1. I have a pool of devices (smartcard readers) and I need an automatic system to manage the queue for their job.
  2. In case of failure the device must be set as unusable and removed.
  3. I want to achieve the smallest wait time for request.

Is ExcecutorService suitable?

The ExecutorService backs the submission with a BlockingQueue . These queues are obviously FIFO and so by default the thread pool will execute as soon as possible for each request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM