简体   繁体   English

在容器内使用点火器安全吗?

[英]Is it safe to use ignite within a closure?

Im working an ignite service which is going to publishes some tasks via run . 我正在工作一个ignite服务,该服务将通过run发布一些任务。 The service looks like that: 该服务如下所示:

public interface MySvc{
    public void foSomeJob();
}

public MySvcImpl implements MySvc, Service{

    @IgniteInstanceResource
    private Ignite ignite;

    public void foSomeJob(){
        IgniteCompute compute = ignite.compute();
        compute.run(() -> {
             ignite.binary()         //<----Is it safe? 
                   .builder("TYPE"); // What is gonna happen on another node
             //build binary object and put it into a cache
        }
    }
}

The question is what is going to happen on another node? 问题是在另一个节点上将发生什么? We serialize the Ignite instance (really??) and sent it though the network. 我们序列化了Ignite实例(真的??)并通过网络发送了它。 Or how is it working? 或如何运作?

In my case performance of the task is critical... So I'd like to understand how is it working in case of running the task on the other node? 就我而言,任务的性能至关重要……因此,我想了解一下在另一个节点上运行任务时它是如何工作的?

Maybe I should use Ignition.ignite(); 也许我应该使用Ignition.ignite(); explicitly? 明确?

Ignite instance will be indeed "serialized", and on remote node you will actually get the instance that is local to that node. Ignite实例将确实被“序列化”,并且在远程节点上,您实际上将获得该节点本地的实例。 Ignite is not physically sent across network, of course. 当然, Ignite不是通过网络物理发送的。

Having said that, this code is correct and will work. 话虽如此,该代码是正确的,并且会起作用。 However, using lambdas or anonymous classes for closures that are sent across network is not a very good practice. 但是,对于通过网络发送的闭包使用lambda或匿名类不是一个很好的做法。 I would recommend to create a separate class and inject Ignite using @IgniteInstanceResource or Ignition.ignite() . 我建议创建一个单独的类,并使用@IgniteInstanceResourceIgnition.ignite()注入Ignite。 This way you will have more control on what is serialized and sent over network. 这样,您将可以更好地控制序列化的内容和通过网络发送的内容。 It's safer and better from performance standpoint. 从性能的角度来看,它更安全,更好。

In your case, if you use lambda, it will serialize this ignite object. 在您的情况下,如果使用lambda,它将序列化此ignite对象。

Instead of it, you can create class to use it as argument in compute() and use @IgniteInstanceResource annotation in this class. 代替它,您可以创建类以将其用作compute()中的参数,并在此类中使用@IgniteInstanceResource批注。

@IgniteInstanceResource annotation injects a current ignite instance. @IgniteInstanceResource批注将注入当前的ignite实例。 At the moment of running of this closure you will have an ignite instance, which executes this closure. 运行此闭包时,您将有一个ignite实例,该实例将执行此闭包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM