简体   繁体   English

带障碍的进程间同步

[英]Inter-Process Synchronization with Barrier

I have a program in Java that performs some computation in parallel. 我有一个Java程序,可以并行执行一些计算。 I can either run it on a single machine or using multiple different machines. 我可以在一台机器上运行它,也可以使用多台不同的机器运行它。

When executing on a single machine, thread synchronization is successfully achieved by using CyclicBarrier class from java.util.concurrent.CyclicBarrier package. 在单台机器上执行时,通过使用java.util.concurrent.CyclicBarrier包中的CyclicBarrier类成功实现了线程同步。 The idea is that all the threads must wait for the other threads to arrive at the same point before proceeding with the computation. 我们的想法是,在继续计算之前,所有线程必须等待其他线程到达同一点。

When executing on multiple different machines, inter process communication is implemented via RMI (Remote Method Invocation). 当在多个不同的机器上执行时,通过RMI(远程方法调用)实现进程间通信。 I have the same problem on this situation and I want the threads of these processes to wait for the others to arrive at the same point before continuing. 我在这种情况下遇到了同样的问题,我希望这些进程的线程在继续之前等待其他进程到达同一点。 I cannot use a shared CyclicBarrier object between the different processes because this class is not serializable. 我不能在不同的进程之间使用共享的CyclicBarrier对象,因为这个类不可序列化。

What are my alternatives to get this barrier behavior on threads executing on different processes on multiple machines? 在多台机器上的不同进程上执行的线程上获取此屏障行为的替代方法是什么?

Thanks 谢谢

You don't need to pass a CyclicBarrier between processes. 您不需要在进程之间传递CyclicBarrier。 You can do an RMI call which in turn uses a CyclicBarrier. 您可以进行RMI调用,然后使用CyclicBarrier。 I suggest you look at HazelCast at it support distributed Lock and many other collections. 我建议你看看HazelCast,它支持分布式Lock和许多其他系列。

IMHO I would reconsider whether you really need all the processes to check point and find a way to avoid needing this in the first place. 恕我直言,我会重新考虑你是否真的需要所有的过程来检查点,并找到一种方法,以避免首先需要这个。

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

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