File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Running Runtime.getRuntime().exec() problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Running Runtime.getRuntime().exec() problem" Watch "Running Runtime.getRuntime().exec() problem" New topic
Author

Running Runtime.getRuntime().exec() problem

Alan Blass
Ranch Hand

Joined: Mar 21, 2010
Posts: 118
Hi!

I am running Runtime.getRuntime().exec() to run VLC (VideoLan) software within a servlet. The VLC software runs properly. I use it to record a multicast video streaming.

After running this command, the servlet returns to my AJAX call and my webpage loads.

Problem is: Any subsequent HTTP get or post, the server (Apache Tomcat 7) does not respond.

It is only about after 2 minutes, the server responds back to my browser.

Anyone has the same problem with VLC?

Anyone has any suggestions to advice me to investigate further?

All comments welcomed.

Thanks.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

There are several traps that one can fall into using Runtime.exec() so you should read the 4 sections of http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html and implement all the recommendations. If this fails to solve the problem then posting the code might help.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

But I wonder what use running a GUI client like VLC is from a servlet? When the user is remote, the GUI will appear on the server machine. Is that the intention?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Alan Blass
Ranch Hand

Joined: Mar 21, 2010
Posts: 118
Hi! Thanks for your replies.

When the remote user wants to start recording, I start VLC on the server and start recording the multicast video. Here is my code:



What could be holding up VLC or tomcat that it stopped responding for 2 minutes?

Many thanks.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
Perhaps VLC is writing to the std err stream, which you are not consuming. A full buffer would cause VLC to hang.

Also - you are doing this all in the request processing Thread - not a good idea. I would certainly execute all that code in a separate Runnable object using its own Thread.

Bill

Java Resources at www.wbrogden.com
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Alan Blass wrote:
What could be holding up VLC or tomcat that it stopped responding for 2 minutes?


You have the potential for deadlock on both the process stdout and stderr. You really do need to read the 4 sections of the traps article and to implement all the recommendations.. Added to this, your servlet is not thread safe since you have state stored as instance variables.

Both these are critical flaws.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running Runtime.getRuntime().exec() problem
 
Similar Threads
Executing VLC in Java swing
Tomcat 6.0 Windows 7 running wscript command
how to retrieve the value of ps - A command
How to execute a command from Java in Linux?
Starting a third-part app consumes 50% CPU!