Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #12812
| From | Jan Burse <janburse@fastmail.fm> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Making System.in interruptible, how? |
| Date | 2012-03-09 20:01 +0100 |
| Organization | albasani.net |
| Message-ID | <jjdk1d$unj$1@news.albasani.net> (permalink) |
| References | <ji0937$tcb$1@news.albasani.net> |
Jan Burse schrieb:
> Dear All,
>
> Found the following nice article, highlighting how
> it would be possible to make System.in interrupible:
>
> http://www.javaspecialists.eu/archive/Issue153.html
>
> Is this the preferred way to do? i.e. to use some
> polling, or are there other ways around?
>
> Best Regards
I have finally adopted the ready() solution. I guess that
if the input stream is redirected to a file, the ready()
will mostly return true, so that performance is no issue.
An issue I had was that I wanted also the possibility that
the input stream is hitchiked by an INT handler. The following
worked for me:
try {
for (;;) {
notPauseScreen();
if (!super.ready()) {
Thread.sleep(SLEEP);
} else {
return super.read(cbuf, offset, length);
}
}
} catch (InterruptedException x) {
throw new InterruptedIOException();
}
The INT handler will pause the screen. So when the screen is
paused neither ready nor read are called. And the INT handler
can call read on System.in, so as to query the end user for
some action.
When the INT handler has determined the action, it can
resume the screen. And the normal application will continue
getting input.
Bye
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar
Re: Making System.in interruptible, how? Jan Burse <janburse@fastmail.fm> - 2012-03-09 20:01 +0100
Re: Making System.in interruptible, how? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-09 21:21 -0500
Re: Making System.in interruptible, how? Jan Burse <janburse@fastmail.fm> - 2012-03-10 19:30 +0100
Re: Making System.in interruptible, how? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-12 16:18 -0400
Re: Making System.in interruptible, how? Jan Burse <janburse@fastmail.fm> - 2012-03-10 20:30 +0100
csiph-web