aspose file tools*
The moose likes Threads and Synchronization and the fly likes running two processess simultaneously Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "running two processess simultaneously" Watch "running two processess simultaneously" New topic
Author

running two processess simultaneously

Vazzdoin Rocko
Ranch Hand

Joined: Feb 24, 2010
Posts: 40
Hi,
i've made two modules in java to complete my project. I want to run my two modules simultaneously. I've called these two modules from a third java program , which calls the two java modules( .jar files)
with the two Runtime Processess(i.e. p1 and p2).
Supposed code :

The problem is that, the second process executes only when the first process is completed ie.when the first module completes. Whereas i want to call these two processess p1 and p2 simultaneously, so that they can keep running and inducing their own results.
i've also tried this with multiple threading too, but the problem is intact.
I guess this sort of problem requires Multiple processing sort of solution.i've dug that concept on google but didn't find something fruitfull.Post some helpfull links if available and implementable.
Kindly reply with the short samples if possible. Thanks in advance.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

i've also tried this with multiple threading too, but the problem is intact.

How did you do ? There shouldn't be any problem launching them using multiple threads.


[My Blog]
All roads lead to JavaRanch
Vazzdoin Rocko
Ranch Hand

Joined: Feb 24, 2010
Posts: 40
Here is the code of third Java programm calling the two modules using threads :
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I thought you wanted to execute two Java applications. What are module1 and module2 ? Scripts ?
Vazzdoin Rocko
Ranch Hand

Joined: Feb 24, 2010
Posts: 40
Yes sir, you are right. module1 and module2 are two java applications i.e. two .jar files.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Do you need to use rt.exec ? You could instantiate the main class and run its main method instead.
Vazzdoin Rocko
Ranch Hand

Joined: Feb 24, 2010
Posts: 40
That won't matter i guess. Kindly write the code sample what you wanna say exactly , may b i might not b getting clear what u'r saying.The main problem is, i want to call these two modules to execute simultaneously and not one by one.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3014
    
  10
Vazzdoin Rocko wrote:The problem is that, the second process executes only when the first process is completed ie.when the first module completes.

That shouldn't be the case. It should be possible to use this technique to run the processes concurrently. Unfortunately, your code shown later does not achieve this. The primary problem is you've got all that code running inside the "testing" constructor, not inside the run() method. That means that it all gets run as part of the one main thread that starts everything - not as part of a separate thread that actually runs concurrently with other things. To achieve the latter, you need to put the code inside the run() method, not the constructor. The run() method is the part that gets run in a separate thread.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

To achieve the latter, you need to put the code inside the run() method, not the constructor.

I didn't even look at this
Vazzdoin Rocko
Ranch Hand

Joined: Feb 24, 2010
Posts: 40
Ohkk .. i guess i have tried that earlier .. but not sure. Let's c this time , i should try it now and test if it works fine and let you know. Thanks !!
Vazzdoin Rocko
Ranch Hand

Joined: Feb 24, 2010
Posts: 40
I am having some errors in the code after modifications.. I guess i have some sytax errors. Cud you please make the modifications in the above code and help me to write the correct code. thanks.
Vazzdoin Rocko
Ranch Hand

Joined: Feb 24, 2010
Posts: 40
Yoohooo... It worked .. !! either of my processes are running simultaneousy now. Thanks Mike Simmons , thanks Christophe Verré for your assistance.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: running two processess simultaneously