Advertisement
Guest User

Untitled

a guest
May 25th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. Foo instance = new Foo();
  2.  
  3. public class Bar {
  4. protected static final ReentrantLock lock = new ReentrantLock();
  5.  
  6. public void process() {
  7. Foo instance = new Foo();
  8. boolean locked = false;
  9. try{
  10. if(SomeCondition) {
  11. locked = true;
  12. Bar.lock.lock();
  13. }
  14.  
  15. *//rest of the processing goes here
  16.  
  17. } finally {
  18. if(locked){
  19. Bar.lock.unlock();
  20. }
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement