my dog learned polymorphism*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "waitFor to get data from server" Watch "waitFor to get data from server" New topic
Author

waitFor to get data from server

Fiona Applesmith
Greenhorn

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 ???

Yousuff


My Thoughts : http://passion4java.blogspot.com
Try not to become a man of success but rather to become a man of value.
Fiona Applesmith
Greenhorn

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: 253

Hey,
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.

Regards
Salil Verma
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: waitFor to get data from server
 
Similar Threads
Runtime process interaction
Calling Java from Java
Use of waitFor() method after exec()
exitValue returns inconsistent values.
qshell script execute on Java PGM