File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Pass values between JVMs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pass values between JVMs" Watch "Pass values between JVMs" New topic
Author

Pass values between JVMs

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1382
How to pass values from one JVM to another ? System.setProperty() and System.getProperty() works within the single JVM. Any thoughts ?
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

There is a concept called serialization in Java. Read this


~ Mansukh
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

kri shan wrote:How to pass values from one JVM to another ?


Your basic options are network, file, and shared memory. Java doesn't include a shared memory feature in the core API, so that option is out, unless you want to use JNI or JNA to interface with native code.

Or you could connect the System.out of one JVM directly to the System.in of the other.

Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1512
    
    5

Jeff Verdegan wrote: Or you could connect the System.out of one JVM directly to the System.in of the other.

I didn't get this Jeff... Do you mean to say that we'll have to use an intermediate file as buffer?


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Anayonkar Shivalkar wrote:
Jeff Verdegan wrote: Or you could connect the System.out of one JVM directly to the System.in of the other.

I didn't get this Jeff... Do you mean to say that we'll have to use an intermediate file as buffer?


I meant an "out-of-band" approach. In Linux shells it's accomplished by the pipe operator.



Everything the first java command sends to System.out can be read by the second java command's system.in.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1512
    
    5

Jeff Verdegan wrote: I meant an "out-of-band" approach. In Linux shells it's accomplished by the pipe operator.

Got it. Thanks
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 908
    
    5
> In Linux shells it's accomplished by the pipe operator.

In Windows cmd.exe too.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Can't we use serialization Jeff? Is that not a correct option in this use case?
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 908
    
    5
Serialization is a way to turn Java objects into a data stream or the other way around. It can help package the data to be exchanged.

But the conduit, the channel to exchange them is another question. You write (and read) ser'ed data to (and from) memory, a file, a socket, a pipe.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Ivan Jozsef Balazs wrote:Serialization is a way to turn Java objects into a data stream or the other way around. It can help package the data to be exchanged.

But the conduit, the channel to exchange them is another question. You write (and read) ser'ed data to (and from) memory, a file, a socket, a pipe.


@ Krishan : Sorry man, I gave an irrelevant answer. Take it back.

@ Ivan : Can you perhaps provide a link where I can understand these concepts of pipes / sockets / shared memory? I have no idea what they are or how these can be programmed. Basic entry level tutorial to networking concepts maybe would be of much help.

Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 908
    
    5
You should decide first whether files, (named or unnamed) pipes, sockets (or to an give exotic example shared memory) are best suited for your application.
These are general (non-Java) notions. I have not searched tutorials etc. on them recently, but Google (or your favorite search engine) is your friend.
I am sure an introductory level understanding on sockets can be acquired form a decent Java networking tutorial.
Java Custom Networking

Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Thank you Ivan.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pass values between JVMs