Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Consumer {
- private BlockingQueue<Item> items;
- private int blockingQueueSize;
- private int numOfThreads;
- private ExecutorService executor;
- @PostConstruct
- public void init() {
- items = new ArrayBlockingQueue<Item>(blockingQueueSize);
- executor = Executors.newFixedThreadPool(numOfThreads);
- for (int i = 0; i < numOfThreads; i++) {
- executor.execute(new Runnable() -> {
- @Override
- public void run() {
- try {
- while(true) {
- Item item = items.take();
- try {
- processItem(item);
- } catch(exception) { /// };
- }
- } catch(Exception e) {
- log.error(...);
- }
- }
- });
- }
- }
- public void processItem(Item item) {
- try {
- items.put(item);
- } catch(exception) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement