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 89515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:43:43+00:00 2026-05-10T22:43:43+00:00

Given an instance x of Callable<T> , how can I run x in a

  • 0

Given an instance x of Callable<T>, how can I run x in a separate process such that I can redirect the standard input and output of the process? For example, is there a way to build a Process from a Callable? Is there a standard Executor that gives control over input and output?

[UPDATE] It’s not important that the Callable execute in a new process as opposed to a new thread. What I want is to put the Callable instance in a ‘harness’, so that I can control its stdin/stdout. AFAIK, this calls for a new process.

  • 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. 2026-05-10T22:43:44+00:00Added an answer on May 10, 2026 at 10:43 pm

    More generally:

    Given an instance x of Callable utilizing global variables A and B, how can I run x concurrently such that x sees custom values for A and B, rather than the ‘original’ values of A and B?

    And the best answer is, don’t use global variables. Dependency inject things like that. Extend Callable and add methods setStdIn, setStdOut (and setStdErr if you need it).

    I know this isn’t the answer you’re looking for, but the solutions I have seen for this all require a new process, and the only way you are getting that Callable into a new process is to change the code of the Callable so it is serializable, or provides a class name, or some other hack, so instead of making changes that will give you a nasty, brittle solution, just do it right*

    * ‘right’ being to use the widely accepted pattern of dependency injection to provide loose coupling. YMMV

    UPDATE: In response to comment 1. Here is your new interface:

    import java.io.InputStream; import java.io.PrintStream; import java.util.concurrent.Callable;   public interface MyCallable<V> extends Callable<V> {   void setStdIn(InputStream in);   void setStdOut(PrintStream out);   } 

    and your tasks would look like:

    import java.io.InputStream; import java.io.PrintStream;   public class CallableTask implements MyCallable<Object> {      private InputStream in = System.in;     private PrintStream out = System.out;      public void setStdIn(InputStream in) {         this.in = in;     }      public void setStdOut(PrintStream out) {         this.out = out;     }      public Object call() throws Exception {         out.write(in.read());         return null;     } 

    }

    No need for a process. Any solution (even one using processes) is almost certainly going to require code changes to the Callables in some way. This is the simplest (just replace System.out with this.out).

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

Sidebar

Ask A Question

Stats

  • Questions 248k
  • Answers 248k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There is nothing integrated in .NET related to that. But… May 13, 2026 at 8:58 am
  • Editorial Team
    Editorial Team added an answer You need to put it in quotes - it's a… May 13, 2026 at 8:58 am
  • Editorial Team
    Editorial Team added an answer transaction log file writes index updates foreign key lookups foreign… May 13, 2026 at 8:58 am

Related Questions

I need to write a class that allows a subclass to set an attribute
Given an instance of some class in Python, it would be useful to be
I need to copy an object that has a pretty deep hierarchy of member
I have an abstract functor class that overloads operator() and derived objects that implement

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.