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
JavaBot3d 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
JavaBot2d 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
asdru2d ago
Anyone?
JavaBot
JavaBot2d 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
dan1st2d 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
JavaBot2d 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
asdru2d 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
dan1st2d 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
asdru2d ago
I did try that and i still had the same issue
dan1st
dan1st2d ago
I think I might have confused sender with receiver but whatever Can you show that attempt and what exactly gets stuck?
asdru
asdru2d ago
I switched to using a buffered reader since its nextline function isnt blocking and that fixed it
dan1st
dan1st2d ago
BufferedReader#nextLine should be blocking normally - not sure what you mean but if it works, I guess it's ok
asdru
asdru2d ago
:shrugging:
JavaBot
JavaBot2d ago
Post Closed
This post has been closed by <@372715536121069578>.
Want results from more Discord servers?
Add your server