Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mprew.be.service.auto.freecause;
- public class Foo {
- final static Object lock = new Object();
- public static void main(String[] args) {
- new Foo().doMain(args);
- }
- private void doMain(String[] args) {
- new Thread(new OurRunnable()).start();
- new Thread(new OurRunnable()).start();
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- Object other = new Object();
- synchronized (lock) {
- synchronized (other) {
- try {
- other.wait();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
- private static class OurRunnable implements Runnable {
- @Override
- public void run() {
- synchronized (lock) {
- try {
- lock.wait(10000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment