Java 中共享内存的任何概念 [英] Any concept of shared memory in Java

查看:31
本文介绍了Java 中共享内存的任何概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AFAIK,Java 中的内存是基于堆的,内存是动态分配给对象的,没有共享内存的概念.

AFAIK, memory in Java is based on heap from which the memory is allotted to objects dynamically and there is no concept of shared memory.

如果没有共享内存的概念,那么Java程序之间的通信应该是很耗时的.在 C 中,与其他通信模式相比,通过共享内存进行进程间通信更快.

If there is no concept of shared memory, then the communication between Java programs should be time consuming. In C where inter-process communication is quicker via shared memory compared to other modes of communication.

如果我错了,请纠正我.还有什么是让 2 个 Java 程序互相交谈的最快方式.

Correct me if I'm wrong. Also what is the quickest way for 2 Java progs to talk to each other.

推荐答案

由于没有官方的API来创建共享内存段,需要求助于helper library/DDL和JNI来使用共享内存拥有两个Java进程相互通信.

Since there is no official API to create a shared memory segment, you need to resort to a helper library/DDL and JNI to use shared memory to have two Java processes talk to each other.

实际上,这很少成为问题,因为 Java 支持线程,因此您可以在同一个 Java VM 中运行两个程序".这些将共享同一个堆,因此通信将是即时的.另外,您不会因为共享内存段的问题而出错.

In practice, this is rarely an issue since Java supports threads, so you can have two "programs" run in the same Java VM. Those will share the same heap, so communication will be instantaneous. Plus you can't get errors because of problems with the shared memory segment.

这篇关于Java 中共享内存的任何概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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