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

  • SEARCH
  • Home
  • 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 6749169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:39:28+00:00 2026-05-26T12:39:28+00:00

I’m writing a webapp that basically allows users to kick off shell scripts with

  • 0

I’m writing a webapp that basically allows users to kick off shell scripts with parameters they enter through various forms. After doing some research I believe ProcessBuilder to be the best way to run the shell scripts, however I’ve got some conditions that I need to meet and was hoping some others could tell me if I’m thinking along the correct lines.

The scripts that will be kicked off can literally take a few hours to run. So obviously I can’t have the app pause and wait for that long. So I’m wondering if threads is the answer to that problem? I’m not very experienced with using threads and looking for some advice. Should I kick off the ProcessBuilder in a new thread so that the main web app will continue to run? Will that even work? Is it as simple as just declaring a new thread and assigning the process builder to it? Do I have to worry about having various threads running or created? Just not sure of what to be on the look out for or what pitfalls to keep aware of.

Also, I really need a way to be able to at least check on the status of the process once it is running. The requirements call for some way to show how far along the process is, but I don’t know that that is possible. I believe being able to at the very least show that it is still running should be acceptable. How would I go about detecting that?

For some more info it’s a Java/Spring web app and will be running on some flavor of Unix. Thanks for any thoughts and help.

  • 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-26T12:39:29+00:00Added an answer on May 26, 2026 at 12:39 pm

    You could implement something like a JobManager and a Job.

    A Job could be a Runnable which has a ProcessBuilder. In it’s run method, it starts the process (ProcessBuilder.start), waits for it to exit and calls back to the JobManager when finished, possibly returning the exit status of the process.

    The JobManager creates Jobs (each in a new Thread), maintains a collection of current jobs (and maybe a collection of recently finished jobs, maybe a list of failed jobs). Clients can give the JobManager jobs to execute and query for the status (running, finished, failed) of all jobs or a particular job.

    Regarding status of the process, the Job could have startTime, endTime and exitStatus variables and associated get methods. You could return these to the client to display a job status table.

    Your Job.run method might look something like this.

    public void run() {
      startTime = System.currentTimeMillis();  
      process = processBuilder.start();
    
      // spawn threads to consume process output streams
      // even if you're not going to read them
    
      while (running) {
        try {
          process.waitFor();
          running = false;
        } catch (InterruptedException e) {
          // you could stop a process by interrupting it's Job thread
          process.destroy();
        }
      }
      exitStatus = process.exitValue();
      endTime = System.currentTimeMillis();
      jobManager.onExit(this);
    }
    

    Regarding “% complete”, that’s only going to be possible if you have some way of measuring it.

    If a task should complete within a certain time, you could use that as a rough way of reporting expected completion time / completion percentage.

    Or maybe you could capture the output of the processes, using that to set a percentComplete variable in your Job. For example, when you see “message X” in the ouput, set percentComplete=25%. This would mean implementing custom code per type of script – maybe a Job subclass or give the Job a member variable responsible for parsing the output.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT
I am writing an app with both english and french support. The app requests
I'm trying to create an if statement in PHP that prevents a single post
I am using Paperclip to handle profile photo uploads in my app. They upload

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.