File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes waitFor to get data from server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "waitFor to get data from server" Watch "waitFor to get data from server" New topic

waitFor to get data from server

Fiona Applesmith

Joined: Sep 04, 2009
Posts: 2
I am trying to build an application where I hit a button from a jsp page, sending me to a servlet that uses runtime.exec to run a sql query on the server, then return the results to be displayed on the same page. Right now, i call proc.runtime.exec("get data"), then proc.waitFor(), then I forward(request, response) to the original page. Right now, this is working when i call runtime.exec on a very fast command, such as "pwd," but it is not working for my command which takes slightly longer to run - it redirects before the process has finished. Shouldn't waitFor() let the process terminate before forwarding the request? If not, are there alternatives I should be using?
Mohammed Yousuff
Ranch Hand

Joined: Oct 17, 2007
Posts: 198
does the page is not showing the results for the command which takes more time to process. Servlets are sync process, so it has to wait untill the internal process has to complete.....

Can you post your sample code which you are trying ???


My Thoughts :
Try not to become a man of success but rather to become a man of value.
Fiona Applesmith

Joined: Sep 04, 2009
Posts: 2
java file:

Note that the "pwd" process gives me the desired behavior.

jsp file:
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 255

Could you please let us from to which package the class Runtime and Process belongs. I could not find it in standard java api.
You can try using wait and notify function to resolve this issue.

Salil Verma
I agree. Here's the link:
subject: waitFor to get data from server
It's not a secret anymore!