Trying to create a code for queue, complex stuff...
I'm writing a code for creating a queue to an online checkers game.
Basically, when a user invites another user to a game, if the recipient is already in the process of receiving invitations from other users, then the sender's invitation will be added to an invitation queue.
From the recipient side (GUI) - once he receives an invitation and the queue is empty, it'll immediately bring up a dialog asking him if he approves that invitation. Now, in the meantime, while the dialog is open (which means the recipient hasn't approved the invitation yet) the recipient receives another invitation from another user, that invitation will be added to a certain queue, and wait for the results of the first invitation. if the user approves the first invitation, then the 2nd invitation will be rejected automatically and won't show up the expected dialog.
Each invitation is handled through a different thread, so multiple invitations can be sent simultaneously and calls a synchronized method which is supposed to take care of the dialog appearance, so that no multiple dialogs will open up at once.
Now the problem is that on the sender's side, there's an option to cancel the invitation request, this sends an object through the output object stream to the recipient that lets him know that the sender's wants to be removed from that list.
How can I cancel a thread from entering that synchronized method as soon as I get the Cancel request at the recipient's side?