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
JavaBot
JavaBot3mo ago
This post has been reserved for your question.
Hey @asdru! Please use /close or the Close 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.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
JavaBot
JavaBot3mo ago
💤 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.
asdru
asdruOP3mo ago
Anyone?
JavaBot
JavaBot3mo ago
💤 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.
dan1st
dan1st3mo ago
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?
JavaBot
JavaBot3mo ago
💤 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.
asdru
asdruOP3mo ago
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
dan1st
dan1st3mo ago
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 similar
asdru
asdruOP3mo ago
I did try that and i still had the same issue
dan1st
dan1st3mo ago
I think I might have confused sender with receiver but whatever Can you show that attempt and what exactly gets stuck?
asdru
asdruOP3mo ago
I switched to using a buffered reader since its nextline function isnt blocking and that fixed it
dan1st
dan1st3mo ago
BufferedReader#nextLine should be blocking normally - not sure what you mean but if it works, I guess it's ok
asdru
asdruOP3mo ago
:shrugging:
JavaBot
JavaBot3mo ago
Post Closed
This post has been closed by <@372715536121069578>.
Want results from more Discord servers?
Add your server