scanner blocking thread close
in a project im working on i have a client with a sender and receiver thread. When the server send the quit command im also sending the clients the "quit" message which should intterupt their sender and receiver threads. The receiver ends just fine but the sender (that has the scanner) is stuck waiting for the next line. What's the appropriate way to handle this? i tried closing the senders' scanner in the receiver among other things but nothing worked
15 Replies
⌛
This post has been reserved for your question.
Hey @asdru! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
Anyone?
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
The
Scanner#nextLine
won't finish until something is entered
it doesn't care about interruption
What you can do is close the scanner from the other thread
or which thread is the problem?
What exactly happens?💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
If i try closing the sender thread drom the reciever nothing happens because the interrupt function gets stuck wating for the sender's scanner to close/recieve input First
I didn't say closing the other thread but closing the scanner
So you could add a
close()
method to the receiver class or whatever that closes the Scanner
and the sender could call that or similarI did try that and i still had the same issue
I think I might have confused sender with receiver but whatever
Can you show that attempt and what exactly gets stuck?
I switched to using a buffered reader since its nextline function isnt blocking and that fixed it
BufferedReader#nextLine
should be blocking normally - not sure what you mean but if it works, I guess it's ok:shrugging:
Post Closed
This post has been closed by <@372715536121069578>.