Results 1 to 12 of 12
  1. #1
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Question [SOLVED] How to destroy a process when a button is clicked?

    hi all,
    I am running a Process in a background thread and i want to stop that process when i click on a button.
    i cudnt access the obj of Process from the button click event. i also tried to declare it as static but in vain.
    pls suggest me possible workarounds.
    Thanks and Regards,
    Pranav

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default

    iam unable to access the 'proc' from the ActionPerformed Event of 'Stop' button.
    I tried to declare the process as static. but it is not allowing me to do so.

    (im invoking this thread in the constructor of my class)
    final Runnable myScript = new Runnable() {

    public void run() {
    proc = Runtime.getRuntime().exec(cmd);
    .
    .
    .
    }
    };

    please tell me a solution for this.
    Thanks and Regards,
    Pranav

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,453
    Rep Power
    25

    Default

    but it is not allowing me to do so.
    Do you get an error message?
    Redesign your code so you have a reference to the object where you need it. Or so you can call a method that has a reference.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Norm View Post
    Redesign your code so you have a reference to the object where you need it. Or so you can call a method that has a reference.
    This is the best way to do it. Just have a try.

  6. #6
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default

    thanks for ur reply.
    i have redesigned my code. it is working well now.
    Thanks and Regards,
    Pranav

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Nice, so if you have solve the question please mark it as solved. And also it's better if you can explain how you solve it, in later someone can useful your solution.

  8. #8
    rajendra413 is offline Member
    Join Date
    Feb 2009
    Posts
    1
    Rep Power
    0

    Default

    hi
    i have started httpd.exe in apache webserver by using java program using Runtime.getRuntime.exec(cmd(to start httpd)) .apache service started and its working as background process.now i want to kill the background process. i am traying process.destroy() but its not working when i am calling stop button in gui interface. any one can help me how to kill the background process using java

  9. #9
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    I suggest you find a more subtle way of telling Apache that it should shut down. Simply killing it suddenly, over and over, can't possibly be good for it.

  10. #10
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default ... maybe make a movie?

    yeah... you might wake up someday and find the living dead Apache process running around ... :)

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Even this is not a good practice. Can't we workaround with the server manager? Basically there should be some options to start and stop the server.

  12. #12
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default

    yeah... i too dint get a solution for this!
    i wrote a shell script to kill the process and invoked that script when clicked on cancel button.
    but i think that this is not the apt way.
    i left that as i hv gt sm othr proj n dint get time to spend on this anymore!

    please suggest possible work-arounds...
    Thanks and Regards,
    Pranav

Similar Threads

  1. Destroy object
    By anjanesh in forum New To Java
    Replies: 11
    Last Post: 01-02-2010, 07:25 PM
  2. Display success message in same page when submit button is clicked
    By am17mu in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-29-2008, 10:56 AM
  3. code for number of clicks clicked on a web page???
    By Sveta_cool in forum Advanced Java
    Replies: 2
    Last Post: 02-01-2008, 02:55 PM
  4. Applets (init, start, stop, destroy)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-12-2007, 10:57 AM
  5. Replies: 0
    Last Post: 09-28-2007, 12:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •