Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply

Java - shared memory in java

 
Thread Tools Search this Thread
Old 03-08-2005, 03:10 PM   #1
qwejohn@hotmail.com
 
Posts: n/a
Default shared memory in java

Hello,

Is there someting which may be termed as "shared memory in java" ?
(I mean something which may connect 2 Java processes but is not a
socket ;
something like CreateFileMapping() in windows or shmget/shmat() (Unix
System V IPC) or
shm_open() (Unix Posix IPC).

Googling for "shared memory in java" in groups gave 7 results which did
not
really satisfy me.

Regards,
John

  Reply With Quote
Old 03-08-2005, 03:30 PM   #2
Vincent Cantin
 
Posts: n/a
Default Re: shared memory in java

> Hello,
>
> Is there someting which may be termed as "shared memory in java" ?
> (I mean something which may connect 2 Java processes but is not a
> socket ;
> something like CreateFileMapping() in windows or shmget/shmat() (Unix
> System V IPC) or
> shm_open() (Unix Posix IPC).


In java, the easier way to share the memory between 2 programs is to use 2
threads in 1 JVM.
Moreover, the java language contains a built-in mechanism to access to the
objects and their data wrt the concurrent threads (the "synchronized"
keyword). In C++ it was hairy, in Java it is smooth and easy.

Vincent Cantin


  Reply With Quote
Old 03-08-2005, 06:03 PM   #3
Bozo Bits
 
Posts: n/a
Default Re: shared memory in java

In general you have to use C/C++ and JNI to create a shared memory
segment. Then there is the issues of moving object state into and out
of memory, this can be pretty complex to do and get it right. Most of
the time you can design around the problem with RMI or standard network
programming.

The other route is to use a commercial product such as Gemstone Systems
Facets or Gemfire product lines which have already solved the shared
memory issues..

V
> > Is there someting which may be termed as "shared memory in java" ?
> > (I mean something which may connect 2 Java processes but is not a
> > socket ;
> > something like CreateFileMapping() in windows or shmget/shmat()

(Unix
> > System V IPC) or
> > shm_open() (Unix Posix IPC).

>


  Reply With Quote
Old 03-08-2005, 06:22 PM   #4
Gordon Beaton
 
Posts: n/a
Default Re: shared memory in java

On 8 Mar 2005 08:10:14 -0800, wrote:
> Is there someting which may be termed as "shared memory in java" ?
> (I mean something which may connect 2 Java processes but is not a
> socket ; something like CreateFileMapping() in windows or
> shmget/shmat() (Unix System V IPC) or shm_open() (Unix Posix IPC).


Not really the same as shared memory, but maybe Java Spaces would
provide a more Java-like solution to whatever it is you're trying to
do.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
  Reply With Quote
Old 03-08-2005, 06:37 PM   #5
timjowers@gmail.com
 
Posts: n/a
Default Re: shared memory in java

One link on memory objects in NIO. I skimmed it but the mem does not
seem mapped to shared mem; i.e. the memory cannot be accessed by other
apps AFAICT. ?

http://www.developer.com/java/other/...0936_1548681_1

TimJowers

  Reply With Quote
Old 03-08-2005, 07:01 PM   #6
timjowers@gmail.com
 
Posts: n/a
Default Re: shared memory in java

I thought maybe RandomAccessFile might be a memory mapped file but JB
pointed out this is not so in the thread: "How to initialize a big
(String-)Array fast?". I have not found a memory mapped file class in
Java. What would be nice is a RAMFile and if this same memory can be
accessed by name from CreateFile(). That would be nice.

This would be a very good assignment for a graduate level Java class:
"Create a Java RAM File object that uses native APIs to provide a
memory mapped file."

  Reply With Quote
Old 03-08-2005, 08:38 PM   #7
John C. Bollinger
 
Posts: n/a
Default Re: shared memory in java

wrote:

> I thought maybe RandomAccessFile might be a memory mapped file but JB
> pointed out this is not so in the thread: "How to initialize a big
> (String-)Array fast?". I have not found a memory mapped file class in
> Java.


You would want to consider the java.nio.MappedByteBuffer class, which
does represent a view of a memory-mapped file.

--
John Bollinger


  Reply With Quote
Old 03-09-2005, 12:04 AM   #8
Bozo Bits
 
Posts: n/a
Default Re: shared memory in java

One thing to keep in mind is whether it can be shared between
processes, which I don't think you can do with
java.nio.MappedByteBuffer. The other issue with this is that for small
files it probably isn't an issue but large files will consume a
significant amount of the virtual address space that an application may
need( same issues exist for users of shared memory).
V
John C. Bollinger wrote:
> wrote:
>
> > I thought maybe RandomAccessFile might be a memory mapped file but

JB
> > pointed out this is not so in the thread: "How to initialize a big
> > (String-)Array fast?". I have not found a memory mapped file class

in
> > Java.

>
> You would want to consider the java.nio.MappedByteBuffer class, which


> does represent a view of a memory-mapped file.
>
> --
> John Bollinger
>


  Reply With Quote
Old 03-09-2005, 05:51 AM   #9
qwejohn@hotmail.com
 
Posts: n/a
Default Re: shared memory in java

Hello,
Thanks;
I am familiar and had used many times concurrent threads and
"synchronized" in Java.

The thing is , I want to share memory between 2 threads/processes , one
in Java and one in "C".

There is of course the JNI solution; I am currently using it; the thing
is that when you call
a JNI method from Java , and there is some problem in the "C" code
(like a pointer which is not handled right and ,for example, is
incremented
so that it points to a non-valid address) it is sometimes difficult to
trace. Of course you can use bound checkers and other memory debugging
tools,
but it is a sometimes cumbersome. Especially , when there is a problem
with a pointer as I depicted above, the crash will be sometiomes in the

Java part (so it seems to me ) ; As I understand , when you allocate
memory
in the JNI "C" method, it gets it memory from a memory manager of
the "c" compiler , but there is an upper memory layer of Java which
controls it somehow. (I am NOT sure about it; memory managers
allocatiOn algorithms are complex , and I don't know much about Java
memory manager
since Sun's code is not an open source ).

If the two threads need only a little in common (lets say one should
only
pass a string of 10 chars to the second ("C") code, as it is in my case
, it seems to me
that using shared memory can be a solution (if it is an option at all).


It may be a little less efficemt than using JNI, but it can be easier
to maintain/debug.

Regards,
John

Vincent Cantin wrote:
> > Hello,
> >
> > Is there someting which may be termed as "shared memory in java" ?
> > (I mean something which may connect 2 Java processes but is not a
> > socket ;
> > something like CreateFileMapping() in windows or shmget/shmat()

(Unix
> > System V IPC) or
> > shm_open() (Unix Posix IPC).

>
> In java, the easier way to share the memory between 2 programs is to

use 2
> threads in 1 JVM.
> Moreover, the java language contains a built-in mechanism to access

to the
> objects and their data wrt the concurrent threads (the "synchronized"
> keyword). In C++ it was hairy, in Java it is smooth and easy.
>
> Vincent Cantin


  Reply With Quote
Old 03-10-2005, 03:12 PM   #10
Vincent Cantin
 
Posts: n/a
Default Re: shared memory in java

> One thing to keep in mind is whether it can be shared between
> processes, which I don't think you can do with
> java.nio.MappedByteBuffer.


This is a abstract class, not final, so you can redefine the implementation
of the functions in a subclass written by your own (.. using JNI to access
the shared memory segment).


  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
OCZ 6GB Triple-Channel 1333 MHz DDR3 Memory Kit Ian Front Page News 0 02-16-2009 12:27 PM
memory upgrade -D- A+ Certification 1 02-03-2007 12:01 AM
Re: What memory to use? me A+ Certification 0 12-14-2004 02:33 AM
Re: Memory stick question Nildram A+ Certification 1 01-14-2004 01:41 PM
Half memory: lost? Joe A+ Certification 4 09-04-2003 07:57 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47