是否可以创建Hazelcast ExecutorService在集群的子集上执行? [英] Can a Hazelcast ExecutorService be created to execute on a subset of the cluster?

查看:192
本文介绍了是否可以创建Hazelcast ExecutorService在集群的子集上执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的项目设置带有hazelcast的分布式执行器服务.某些将要运行的任务只能在具有特定于操作系统的实用程序的计算机上完成.有没有一种方法可以提交将在集群子集上运行一次的任务?还是要注册它应与特定的执行者服务一起使用?

I'm trying to setup a distributed executor service with hazelcast for my project. Some tasks which will run can only be completed on machines with OS specific utilities. Is there a way to submit a task that will run once on a subset of the cluster? Or to register that it should be used with a specific executor service?

看一下API,有很多选项可以提交任务,但是所有提交给多个成员的选项都会在所有这些成员上运行任务,而不是其中一个.

Looking at the API there are a number of options to submit a task, but all the options for submitting to multiple members will run the task on all of those members, not one of them.

我查看了javadoc,发现有多种方法可以将Runnable对象提交给执行者服务:

I have looked at the javadoc and seen that there are a number of ways to submit Runnable objects to the executor service:

void executeOnMember(Runnable command, Member member)-这仅允许我指定一个成员,我需要指定一组成员.

void executeOnMember(Runnable command, Member member) - this only allows me to specify one member, I need to specify a group of members.

void executeOnMembers(Runnable command, Collection<Member> members)-这使我可以指定一组成员,但是可以多次运行任务,而不是一次.

void executeOnMembers(Runnable command, Collection<Member> members) - This allows me to specify a collection of members, but runs the task multiple times instead of just once.

void submitToMembers(Runnable task, Collection<Member> members, MultiExecutionCallback callback)-再次指定成员的集合,但是它将多次运行任务.

void submitToMembers(Runnable task, Collection<Member> members, MultiExecutionCallback callback) - again this specifies a collection of members, but it will run the task multiple times.

推荐答案

我将复制注释作为答案,因为由于我以外的原因该问题已关闭了一段时间.

I'm going to copy the comment as answer, because this question was closed for some time for reasons beyond me.

我将使用IExecutorService.executeOnMember.如果要在成员子集中的一个成员上执行,请随机选择一个成员,或使用某种负载平衡策略(例如,循环轮询或检测实际负载),然后执行OnMember.

I would make use of the IExecutorService.executeOnMember. If you want to execute on one of the members of a subset of members, select one member randomly or using some kind of loadbalancing policy (e.g. round robin.. or detect actual load) and then executeOnMember.

您还可以由负责此工作的Executor装饰器包装IExecutorService:

You could also wrap the IExecutorService by an Executor decorator that takes care of this:

 class OsSpecificExecutor implements Executor{
     private IExecutorService ex;


     public void execute(Runnable task){
         Set<Member> targetMembers = getYourTargetMembers()
         Member member = random(targetMembers)
         ex.executeOnMember(task, member);
     }
 }

通过这种方式,您可以将其用作常规执行程序,但在下面,您可以控制哪些成员以及可选的负载平衡.

This way you can use it as a normal executor, but underneath you have control on which members + optional load balancing.

这篇关于是否可以创建Hazelcast ExecutorService在集群的子集上执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆