Last active
May 8, 2017 15:16
-
-
Save jklingsporn/62d7eb2e14cefa7a60f3d1ba2d6989e6 to your computer and use it in GitHub Desktop.
Locking gone wrong 1
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 LockTest { | |
private static final Logger logger = LoggerFactory.getLogger(LockTest.class); | |
public static void main(String[] args) throws InterruptedException { | |
ForkJoinPool.commonPool().execute(() -> { mayLock(127);}); | |
ForkJoinPool.commonPool().execute(() -> { mayLock(127);}); | |
ForkJoinPool.commonPool().shutdown(); | |
ForkJoinPool.commonPool().awaitTermination(1, TimeUnit.MINUTES); | |
} | |
private static void mayLock(Integer arg) { | |
logger.info("entering method {} ",arg); | |
synchronized (arg){ | |
logger.info("entering lock "+Thread.currentThread().getName()); | |
try { | |
Thread.sleep(2000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment