my dog learned polymorphism*
The moose likes Performance and the fly likes How to free CPU utilised? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "How to free CPU utilised?" Watch "How to free CPU utilised?" New topic
Author

How to free CPU utilised?

yathish Gatty
Ranch Hand

Joined: Oct 05, 2004
Posts: 31
Hi,
I am running an .exe file using :

Runtime rt = Runtime.getRuntime();

Process proc = rt.exec(cmd);

Where cmd is String to execute .exe file.

When I run this .exe file continuosly.Say after executing 1000 times it hangs.

When I checked in windows task manager it showed .exe 100% CPU utilised.Then I had to manually release the resource.

How can I avoid this from happening?

Is there a way by which I can programatically release the 100% CPU utilised resource.

Thank You,

With regards,

Yathish
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
proc.destroy() should kill the process, according to the javadoc: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Process.html


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
yathish Gatty
Ranch Hand

Joined: Oct 05, 2004
Posts: 31
Thanks for the reply,

I have done as you said

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd);
int ret=proc.waitFor();
proc.destroy();

But this still it hangs.

Thank you.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
There's not much point doing destroy() after waitFor() has returned. When the waitFor() returns, the process has finished anyway. The point of destroy() is to request a process that's still running to terminate.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
Are you really exec-ing without consuming the System out and err character streams generated by the Process?
Perhaps you are throwing away the information that could tell you what is going on.
Bill
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

What Bill said.
Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.

java.lang.Process


[How To Ask Questions On JavaRanch]
yathish Gatty
Ranch Hand

Joined: Oct 05, 2004
Posts: 31
Hi,
I tried to handle the Standard error and standard inputstream by using the following code but this still hangs.Just verify whether this was the solution you specified if not please help me out in this.

The code I have implemented is as follows:



Please help me out in this .

Thank you.

From ,

Yathish

[added code tags to preserve formatting - Ilja]
[ April 26, 2005: Message edited by: Ilja Preuss ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
That looks reasonable for catching and displaying the system out and err character streams - now, are you seeing anything unexpected or getting any error codes?

Looking back at your original post:
When I run this .exe file continuosly.Say after executing 1000 times it hangs.

The following questions occur to me:
1. Are you waiting for the end of one Process before repeating or trying to fire off 1000 execs at one time?
2. Watching the task manager - does it show gradual increase in CPU utilization or is the change sudden? How about memory utilization/
3. This proces you are execing - what system resources does it use? File handles, Graphic contexts, DB connections, etc.

Bill
yathish Gatty
Ranch Hand

Joined: Oct 05, 2004
Posts: 31
Hi,

The code does not display any error codes.

I am waiting for one process to complete and then continuing with the next.i.e execing one at a time.

The change in cpu utilization is sudden.
As far as system memory utilization is concerned there are no issues.It remains constant throughout.

The .exe file i am using is filter.exe of Microsoftword 2000.

Thank you,

with regards,

Yathish
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
I think that if this was my problem, I would insert a delay of at least a second between the end of one process and the next exec. I know that sounds strange, but I am suspecting that after you are getting the end of the process, Windows still has some cleaning up to do.
I know my WinXP systems sometimes seem to wander off and do a bunch of housekeeping stuff totally out of my control.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to free CPU utilised?