Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2006, Red Hat Middleware LLC, and individual contributors 
   * as indicated by the @author tags. 
   * See the copyright.txt in the distribution for a
   * full listing of individual contributors. 
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
   * of the GNU Lesser General Public License, v. 2.1.
  * This program is distributed in the hope that it will be useful, but WITHOUT A 
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
  * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  * You should have received a copy of the GNU Lesser General Public License,
  * v.2.1 along with this distribution; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
  * MA  02110-1301, USA.
  * 
  * (C) 2005-2006,
  * @author JBoss Inc.
  */
 /*
  * Copyright (C) 2000, 2001,
  *
  * Arjuna Solutions Limited,
  * Newcastle upon Tyne,
  * Tyne and Wear,
  * UK.  
  *
  * $Id: LockConflictManager.java 2342 2006-03-30 13:06:17Z  $
  */
 
 package com.arjuna.ats.internal.txoj;
 
 import java.util.Date;
 
An instance of this class is used to determine what to do in the event of a lock conflict for a given object. If the timeout and retry values are >=0 then we use them to sleep the thread which tried to get the lock. If the retry value is -100 (LockManager.waitTotalTimeout) then the thread will block for up to the total timeout and be signaled either when the timeout occurs, or when the lock is actually released.
 
 
 public class LockConflictManager
 {
     public LockConflictManager()
     {
          = new Object();
     }

    
Wait for the specified timeout and retry. We may either sleep the thread, or block it on a mutex. Returns the time taken to wait.
 
 
     public int wait (int retryint waitTime)
     {
         Date d1 = Calendar.getInstance().getTime();
         
         if (retry == .)
         {
             try
             {
                 Thread.sleep(waitTime);
             }
             catch (final Throwable ex)
             {
             }
         }
         else
         {
             synchronized ()
             {
                 try
                 {
                     .wait(waitTime);
                 }
                 catch (InterruptedException e)
                 {
                 }
             }
         }
 
         Date d2 = Calendar.getInstance().getTime();
 
         return (int) (d2.getTime() - d1.getTime());
     }

    
Signal that the lock has been released.
 
 
     public void signal ()
     {
         synchronized ()
        {
            .notifyAll();
        }
    }
    private Object _lock;
New to GrepCode? Check out our FAQ X