Tobia
Tobia

Reputation: 9506

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?

Upvotes: 0

Views: 112

Answers (1)

John Vint
John Vint

Reputation: 40256

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.

Upvotes: 1

Related Questions