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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:50:56+00:00 2026-05-30T02:50:56+00:00

I have two threads – one awaits for input and the other is printing

  • 0

I have two threads – one awaits for input and the other is printing the debugging info.

However only one console window, so I can’t type ‘exit’ (or whatever to stop the process), because System.out.println constantly prints the stuff. Can I have two separate console windows for each?

P.S. I wouldn’t want to use Swing just for this purpose – there must be a way.

  • 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-30T02:50:57+00:00Added an answer on May 30, 2026 at 2:50 am

    The only way I could think of would be to have two difference processes and a link betweeen the two processes. But I don’t have a clue as to how to do that. Perhaps your best bet is to use the JOptionPane class.

    While you stated that you don’t want to use Swing, I believe that JOptionPane would be the best option for you. Simply using JOptionPane.showInputDialog is a fast way to solve your issue. Here’s a link to JOptionPane’s JavaDoc.

    If you really can’t use Swing, there’s always the option to press Ctrl + C to stop the process.

    A final option would be to buffer the output and only write it after the input. After you receive input, you would flush the buffer and then deal with the input. In this manner, you would prevent the application from closing before the buffer is flushed. There are two ways to do this:

    1. You can use a BufferedWriter with a very large size (maybe 100,000?) and store this as a static variable. Instead of calling System.out.println(), you could call MyClass.out.println()
    2. You could override System using System.setOut(). You would create your own PrintWriter that would take any input and send it to a LinkedList (or your own LinkedList designed for chars, if you choose). I suggest you use a linked list because appending is O(1) for a linked list while appending is O(n) for an array list.

    Edit:

    As for hmjd’s suggestion (file writing), you would do that like this:

    System.setOut(new FileWriter(new File(myFileName)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two threads, one thread processes a queue and the other thread adds
So, I have two threads. Thread one manages the client connections. (There is only
I have two threads, one for data acquisition and the other one for display.
I have two threads, the main one for GUI and the other for intense
I want to have two threads to handle windows messages. One for key/mouse input
I have two threads, one needs to poll a bunch of separate static resources
I have two threads, one updating an int and one reading it. This is
I have two threads in an Android application, one is the view thread, and
I have two threads, one that dispatches messages and another that parses them. Simple,
I have two threads. First one is something like this: while(1) { pthread_mutex_lock(&mutex); //DO

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.