Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3434810
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:44:38+00:00 2026-05-18T07:44:38+00:00

I have developed a JSP web application which, on every request, spawns a new

  • 0

I have developed a JSP web application which, on every request, spawns a new Java Thread. In every newly spawned thread I create a Process using Runtime.exec() and store the process object in an instance variable in thread. I have a requirement in which I have to kill the created subprocess and also stop the thread. So, I overrode the interrupt method in the thread and in the overridden method I’m calling destroy() on already stored Process object in the instance variable. Following is the code:

public class MyThread extends Thread {
    private Process subprocess;

    @Override
    public void run() {
        subprocess = Runtime.getRuntime().exec("myprocess.exe");
        subprocess.waitFor();
        /*
            Some more statements
        */
    }

    @Override
    public void interrupt() {
        if(subprocess!=null) {
            System.out.println("Destroying Process");
            subprocess.destroy();
        }
        super.interrupt();
    }
}

Is it illeagal to override interrupt method?
Its important that I kill the created process before I interrupt the thread that creates it. I see that the thread does get interrupted because the statements after waitFor() do not get executed. But, however, destroy() doesnt work (but gets called) and the created “myprocess.exe” completes execution even if I call interrupt() method before its completion. Can someone please help me out with this? What am I missing?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:44:39+00:00Added an answer on May 18, 2026 at 7:44 am

    It’s not illegal to override interrupt, but I wouldn’t recommend it. Perhaps a cleaner way to do this would be:

    public class MyThread extends Thread {
        private Process subprocess;
    
        @Override
        public void run() {
            subprocess = Runtime.getRuntime().exec("myprocess.exe");
            try {
                subprocess.waitFor();
            }
            catch (InterruptedException e) {
                subprocess.destroy();
            }
            /*
                Some more statements
            */
        }
    }
    

    Don’t forget that you should also pull data from the subprocess output/error streams, otherwise you might wind up with full buffers and a blocked subprocess. It’s OK to read from those streams and discard the data. I suspect the commons-io package has tools to make this a one-liner, otherwise it’s a fairly simple method to write yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an already developed web application based on struts 1.2 which contains jsp
I have a web application developed with Struts2, JSP, JPA, Spring and MySql. I
I have developed a java 1.4 web application.Application is deployed on jboss(tomcat). suppose my
I have developed a web application on Struts2 and used JSP. I want to
I have developed a java web application using JSF 2.0(Facelets) on GlassFish 3.1.1 with
I have developed an web application using JSP and deployed in tomcat server. In
I have developed a JSP web application using NetBeans IDE and a Virtuoso RDBMS.
I am a student and I have developed a web application based on JSP.
I have a web application currently being developed in JSP/Servlets. The application allows users
I have developed a web application using using servlet and JSP. I am not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.