Skip to content

Instantly share code, notes, and snippets.

@vinaymcu
Created August 24, 2016 04:46
Show Gist options
  • Save vinaymcu/befaa691f614c0244b1b8aa489f5f542 to your computer and use it in GitHub Desktop.
Save vinaymcu/befaa691f614c0244b1b8aa489f5f542 to your computer and use it in GitHub Desktop.
code
class Shared {
synchronized void methodOne(Shared s) {
Thread t = Thread.currentThread();
System.out.println(t.getName() + "is executing methodOne...");
System.out.println(t.getName() + "is calling methodTwo...");
s.methodTwo(this);
System.out.println(t.getName() + "is finished executing methodOne...");
}
synchronized void methodTwo(Shared s) {
Thread t = Thread.currentThread();
System.out.println(t.getName() + "is executing methodTwo...");
System.out.println(t.getName() + "is calling methodOne...");
s.methodOne(this);
System.out.println(t.getName() + "is finished executing methodTwo...");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment