Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Foo instance = new Foo();
- public class Bar {
- protected static final ReentrantLock lock = new ReentrantLock();
- public void process() {
- Foo instance = new Foo();
- boolean locked = false;
- try{
- if(SomeCondition) {
- locked = true;
- Bar.lock.lock();
- }
- *//rest of the processing goes here
- } finally {
- if(locked){
- Bar.lock.unlock();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement