简体   繁体   中英

java executor service on hazelcast queue

I have a hazelcast Queue (shared across the server instances) which has 1000's of records in it. Records are some kind of Jobs (like sending email, SMS etc). I need to process these records by picking them from the queue. To make it fast I am thinking of using executor service so that records get processed by multiple threads asynchronously.

This application will be deployed on multiple servers so i am bit confused with the processing order of records in the queue multiple servers. How should I configure my executor so that it pick up the records from queue and process them. Do i need to set up my executor to get invoked after every second so it keep hitting fetching the records from processing.

I am not sure if I am ble to explain the problem properly but just trying to use the executor service on the shared Queue (across server instances) .

Thanks in Advance!!

You may want to consider using the hazelcast executor service. I've tried using a hazelcast queue for a local thread pool, and my experience has been that it does not distribute tasks properly.

http://www.hazelcast.com/docs/2.5/manual/multi_html/ch09.html

It automatically distributes the job execution across the cluster.

Assuming job implements Callable, you can do the following

Future<T> future =  hazelcastInstance.getExecutorService([optional name]).submit(job);
//if you want the return value of the job, you can do this:
T value = future.get(); //This blocks until the job is done

You can configure multiple distributed thread pools using different names.

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