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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:25:07+00:00 2026-06-07T20:25:07+00:00

I wrote a tool, which is performing some steps 1..n Some of the steps

  • 0

I wrote a tool, which is performing some steps 1..n
Some of the steps require user interaction (reading from System.in)
Other steps loop until some condition is fulfilled or the user pressed some key
(When the user pressed the key the loop should end and the main should go to the next step)

What I did for those steps, that provide a key loop interruption is to spawn a thread which reads from System.in -> this thread then interrupts the step, if key was pressed.
This works fine, but when the loop condition was fulfilled, then this key listener thread would block on System.in, so the next step, that requires user interaction would be affected

My key listener thread’s run was basically:

new InputStreamReader(System.in).read() > 0;

which blocks of course, so I was looking for a way to fix this

  • 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-06-07T20:25:09+00:00Added an answer on June 7, 2026 at 8:25 pm

    And when I change the key listener thread to:

    try
    {
    InputStreamReader reader = new InputStreamReader(System.in);
    while (!reader.ready()) { Thread.sleep(100); }
    if (reader.read() > 0) { // interrupt this step and proceed to the next one }
    }
    catch (IOException e) { // do something }
    catch (InterruptedException e) { // noone needs me anymore }
    

    And after the step loop I just interrupt the key listener thread, since it is not needed anymore.

    So this worked fine for me and since I didn’t find a solution for such problems, wanted to post it here for the future generations 🙂

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

Sidebar

Related Questions

I wrote scripts which permit to synchronise some of my local folders with a
I have a huge report coming out of a tool from which i extract
Currently I have a custom tool which generates vanilla-SQL (only using standard SQL), from
I wrote a tool running on a system (Win7) with two network interfaces, each
I wrote a program, which open docx package and changes some <w:t> -text in
I wrote simple load testing tool for testing performance of Java modules. One problem
I am trying to write a monitoring tool to monitor some information It will
I would like to write a command line tool that passes some formatted text
I wrote a program that rolls a die with a user-specified number of sides.
I have installed Xcode from the Tool cd, I thought that would let me

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.