I am working on a Robotic Analog to digital button listener.
Where There is a synchronized (this) block when the action performed.
public void Init() {
new Timer(200, taskPerformer).start();
)
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent e) {
//not synchronized code
synchronized (this) {
//synchronized code
}
}
}
Now my question is How can I understand which Thread Failed to enter that block? Is there any way so that I can handle those threads. Similar to the if-else , can I handle those thread who could not entered.
Edit: simply want to print("Could not Enter The Block"); How can I do that.?
Thanks.
you can lock on an
Object
(instead ofthis
) which is shared across group of Threads where you need real synchronizationlock object
Thread that holds it
and
Updates based on Comments