Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. private class MyThread extends Thread
  2. {
  3. private static Lock lock = new ReentrantLock();
  4.  
  5. public void run()
  6. {
  7. if (MyThread.lock.tryLock())
  8. {
  9. try
  10. {
  11. // TODO something
  12. }
  13. finally
  14. {
  15. MyThread.lock.unlock();
  16. }
  17. }
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement