wood burning stoves 2.0*
The moose likes Java in General and the fly likes Two Java program communicating.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Two Java program communicating.." Watch "Two Java program communicating.." New topic
Author

Two Java program communicating..

Sunil Kumar Gupta
Ranch Hand

Joined: Aug 26, 2005
Posts: 824
Hi All

I have a problem related to a java code. Please help me to solve the problem..


I have a java code which is say a thread which runs continously...
say

class MyRun extends Thread{
///////definition of MyRun class

//main method here
}

when i run this program, say java MyRun
Now my file is running properly.

Now i need to run another file say

class StopMyRun {
///class definition
//main method here
}

and i will run this file as

java StopMyRun

Now these two files are independent files having their own main method.

My problem is that, I have to stop MyRun Thread from my StopMyRun file.

For ex. I run MyRun program on one shell and when i run StopMyRun on other shell, The first one should stop their function.

How to do that, Any idea



Lack of will power has caused more failure than lack of intelligence or ability.
My Blog | Red5 Resources | Technology Update | Daily Technology Tips
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
You have two different programs running on two different JVMs, you will need some sort of inter process communication. How about a socket, listening for the termination signal?
Sunil Kumar Gupta
Ranch Hand

Joined: Aug 26, 2005
Posts: 824
Originally posted by Edwin Dalorzo:
You have two different programs running on two different JVMs, you will need some sort of inter process communication. How about a socket, listening for the termination signal?


Actually the first program is not generating any signal. I want to terminate that process as soon as i run another process.

Now any idea.
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Why cant you use a flag in DB. Check that flaag at regular intervals & stop you first process ?


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Sunil Kumar Gupta
Ranch Hand

Joined: Aug 26, 2005
Posts: 824
Originally posted by Srinivasa Raghavan:
Why cant you use a flag in DB. Check that flaag at regular intervals & stop you first process ?


Actually i have no idea, when i have to stop that process. Whenever any user starts other process, it will automaticlly shutdown the first process. And problem is that these two process are running on different JVM's

Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
When the second process starts running it should update the flag in th DB. The first process should check this flag in a seperate thread and exit when the flag gets updated..
Sunil Kumar Gupta
Ranch Hand

Joined: Aug 26, 2005
Posts: 824
yes, i think you are right, But what if i am not using DB, Should i do this using any file instead of DB, Where i simply swicth the value , say from 1 to 2, and if 2 then exit first one..
Tomasz Luchowski
Greenhorn

Joined: Sep 16, 2004
Posts: 15
This is probably an overkill, but have you looked at Java Management Extensions (JMX)?


Tomasz Luchowski<br />SCJP, SCBCD, SCWCD, SCEA part 1
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42263
    
  64
Edwins suggestion of using sockets is probably the simplest to implement, and it does not rely on any external resources (a database or a file system).
[ April 22, 2006: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Two Java program communicating..