I have a problem in a high performance environment which can be described in prose as follows:
I have an external Java API which makes a call to an FPGA card with 64 resources on it. I need a mechanism to safely share a subset of those resources between hundreds of threads in an application. Each resource should be considered not thread safe.
So I need a ResourcePool with a method update() which then calls resource.update().
I think this is a fairly common idiom but I am having difficulty fitting my head into the Java concepts. I want to say have 4 of the resources in one ResourcePool. Each should i guess live in their own Thread (so a threadpool would be needed).
How would i implement this so that i could log an error and carry on when all 4 of the resources are in use?
Hope this makes sense!
For the BlockingQueue, it very userful for the producer-consumer pattern, you must renew or add it after this resource by userd, but maybe the initialization of resource is poor perfomance. And it`s a blocking queue, if you want to deal some information when the pool is empty or full, Queue is ok for this.
For the lock, if these resources was initialized and not change after, add lock to these resources is better.
This is my opinion.