Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access an instance in another running Java program?

Tags:

java

I am having a main class called ProccesA, after I run it I am starting another main class (when ProccesA is still running for his own) and I wish to get the instance of ProccesA to use it in my class, can some one direct me how to do that ?

like image 566
spinker Avatar asked Oct 16 '25 17:10

spinker


2 Answers

Processes are not like threads: you cannot get access to instances of classes running in different processes, because they are in a different address space. You need to use interprocess communication facilities to communicate to other processes.

like image 129
Sergey Kalinichenko Avatar answered Oct 18 '25 08:10

Sergey Kalinichenko


Both processes execute in different JVMs, and so use different class loaders. You can't access them directly.

You could however, use RMI to expose the required classes in one of the processes, and access them that way.

like image 32
Rajesh J Advani Avatar answered Oct 18 '25 08:10

Rajesh J Advani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!