Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void doAuthorized(Runnable r) throws InterruptedException {
- try {
- r.run();
- } catch (AuthenticationException e) {
- tryAuth();
- doAuthorized(r);
- }
- }
- Lock authLock = new ReentrantLock();
- private void tryAuth() throws InterruptedException {
- if (authLock.tryLock(5, TimeUnit.SECONDS)) {
- try {
- doAuth();
- } finally {
- authLock.unlock();
- }
- } else {
- throw new IllegalStateException("Cannot acquire auth lock");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement