1

I have an application like the follows,

public class OpenApp {
 public static void main(String[] args) {
 if(args.length>0)
 System.out.println("Hi " + args[0]);
 System.in.read(); 
 }
 public static String sayHi(){
 return "Hi";
 }
}

So The OpenApp will be running. I have some other methods. Can I call the sayHi method from another application, without creating new instance of the class.? Because I have some data constrains on running OpenApp.

Please Correct me If my question is wrong. Simply I'm trying to communicate between 2 JVM. So, I read, RMI is the best way to make the communication. So Is there any other way.

Konstantin Yovkov
63k9 gold badges107 silver badges152 bronze badges
asked Oct 28, 2014 at 6:59
9
  • No actually, trying to avoid specific communication protocols. Like Java reflections, I'm looking for. Commented Oct 28, 2014 at 7:07
  • 1
    @Pasupathi You do need some (at least interprocess) communication protocol if are trying to communicate between 2 JVM. See e.g. javaworld.com/article/2077419/learn-java/…. Other (non-network transparent, means local only) alternatives are FIFO, Named Pipe or Shared Memory. Commented Oct 28, 2014 at 7:08
  • You can use socket, RMI or websevices to communicate between JMV. I feel webservices are the reliable and robus Commented Oct 28, 2014 at 7:13
  • Ya it's reliable. But, there's no challenging in that. Simply exposing webmethods and do those stuff. Socket communication is well enough to do this. But I need something interacting a java process while it's running. Kind of RnD only. Wanted to explore this kind of challenge. Commented Oct 28, 2014 at 7:18
  • you need to bind that module to your application where you want to use that method(sayHi)...thats the only way...if IPS is not preferable.. Commented Oct 28, 2014 at 7:20

1 Answer 1

1

For two applications to communicate, you need some form of Inter-Process Communication, IPC, pretty much by definition. So you need some kind of protocol. So, short answer to your question is: RMI is not the only way, but all other ways are similar, communication and not direct method call.

If you just want to call the method in code of another application, then add the .jar with the class to your application, or load the .jar at runtime, and (since that is a static method) just call the method. But this is just normal static method call, so you probably did not mean this?

answered Oct 28, 2014 at 7:15
Sign up to request clarification or add additional context in comments.

1 Comment

Laoding jar is like creating new instance, I have some data constrains in the running application. I'll check IPC.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.