Created
January 15, 2010 14:49
-
-
Save vaskoz/278103 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ThreadNinja { | |
private int rank; | |
public synchronized void fight(ThreadNinja enemy) { | |
if (!enemy.canDefend(this)) { | |
rank++; | |
} | |
} | |
public synchronized boolean canDefend(ThreadNinja enemy) { | |
if (this.rank > enemy.rank) { | |
this.rank++; | |
return true; | |
} | |
return false; | |
} | |
public static void main(String[] args) { | |
// write code here that will cause a deadlock in the methods above. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment