Package java.util.concurrent.locks

Examples of java.util.concurrent.locks.ReentrantLock


        while(true) {
            do { // wait until not resizing
                who = owner.get(mark);
            } while(mark[0] && who != me);
            ReentrantLock[][] oldLocks = this.locks;
            ReentrantLock oldLock0 = oldLocks[0][hash0(x) % oldLocks[0].length];
            ReentrantLock oldLock1 = oldLocks[1][hash1(x) % oldLocks[1].length];
            oldLock0.lock(); // acquire locks
            oldLock1.lock();
            who = owner.get(mark);
            if((!mark[0] || who == me) && this.locks == oldLocks) { // recheck
                return;
            } else { //  unlock & try again
                oldLock0.unlock();
                oldLock1.unlock();
            }
        }
    }
View Full Code Here


                List<T>[][] oldTable = table;
                table = (List<T>[][]) new List[2][capacity];
                locks = new ReentrantLock[2][capacity];
                for(int i = 0; i < 2; i++) {
                    for(int j = 0; j < capacity; j++) {
                        locks[i][j] = new ReentrantLock();
                    }
                }
                for(List<T>[] row : table) {
                    for(int i = 0; i < row.length; i++) {
                        row[i] = new ArrayList<T>(PROBE_SIZE);
View Full Code Here

    private final ILock writeLock; // writers apply here

    public FifoReadWriteLock() {
        readAcquires = readReleases = 0;
        writer = false;
        metaLock = new ReentrantLock();
        condition = metaLock.newCondition();
        readLock = new ReadLock();
        writeLock = new WriteLock();
    }
View Full Code Here

    private static void start(final int num_threads, final int num_msgs, boolean oob, TimeScheduler timer) {
        final NAKACK nak=new NAKACK();
        final AtomicInteger counter=new AtomicInteger(num_msgs);
        final AtomicLong seqno=new AtomicLong(1);
        final AtomicInteger delivered_msgs=new AtomicInteger(0);
        final Lock lock=new ReentrantLock();
        final Condition all_msgs_delivered=lock.newCondition();
        final ConcurrentLinkedQueue<Long> delivered_msg_list=new ConcurrentLinkedQueue<Long>();
        final Address local_addr=Util.createRandomAddress("A");
        final Address sender=Util.createRandomAddress("B");


        if(timer == null)
            timer=new TimeScheduler2();
        nak.setTimer(timer);
        System.out.println("timer is a " + timer.getClass());

        nak.setDownProtocol(new Protocol() {public Object down(Event evt) {return null;}});

        nak.setUpProtocol(new Protocol() {
            public Object up(Event evt) {
                if(evt.getType() == Event.MSG) {
                    delivered_msgs.incrementAndGet();
                    NakAckHeader hdr=(NakAckHeader)((Message)evt.getArg()).getHeader(NAKACK_ID);
                    if(hdr != null)
                        delivered_msg_list.add(hdr.getSeqno());

                    if(delivered_msgs.get() >= num_msgs) {
                        lock.lock();
                        try {
                            all_msgs_delivered.signalAll();
                        }
                        finally {
                            lock.unlock();
                        }
                    }
                }
                return null;
            }
        });

        nak.setDiscardDeliveredMsgs(true);
        nak.down(new Event(Event.SET_LOCAL_ADDRESS, local_addr));
        nak.down(new Event(Event.BECOME_SERVER));
        View view=new View(local_addr, 1, Arrays.asList(local_addr, sender));
        nak.down(new Event(Event.VIEW_CHANGE, view));

        MutableDigest digest=new MutableDigest();
        digest.add(local_addr, 0, 0, 0);
        digest.add(sender, 0, 0, 0);
        nak.down(new Event(Event.SET_DIGEST, digest));

        final CountDownLatch latch=new CountDownLatch(1);
        Sender[] adders=new Sender[num_threads];
        for(int i=0; i < adders.length; i++) {
            adders[i]=new Sender(nak, latch, counter, seqno, oob, sender);
            adders[i].start();
        }

        long start=System.currentTimeMillis();
        latch.countDown(); // starts all adders

        lock.lock();
        try {
            while(delivered_msgs.get() < num_msgs) {
                try {
                    all_msgs_delivered.await(1000, TimeUnit.MILLISECONDS);
                    System.out.println("received " + delivered_msgs.get() + " msgs");
                }
                catch(InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        finally {
            lock.unlock();
        }

        long time=System.currentTimeMillis() - start;
        double requests_sec=num_msgs / (time / 1000.0);
        System.out.println("\nTime: " + time + " ms, " + Util.format(requests_sec) + " requests / sec\n");
View Full Code Here

    ReentrantLock lock;


    @BeforeMethod
    public void setUp() throws Exception {
        lock=new ReentrantLock();
    }
View Full Code Here

        for(int i=0; i < outputs.length; i++)
            outputs[i]=new ExposedDataOutputStream(outs[i]);

        locks=new Lock[pool_size];
        for(int i=0; i < locks.length; i++)
            locks[i]=new ReentrantLock();
    }
View Full Code Here

        this.arguments = arguments;
        this.environment = environment;
        this.standardOutput = standardOutput;
        this.errorOutput = errorOutput;
        this.standardInput = standardInput;
        this.lock = new ReentrantLock();
        this.stateChange = lock.newCondition();
        this.state = ExecHandleState.INIT;
        executor = new DefaultExecutorFactory().create(String.format("Run %s", displayName));
        shutdownHookAction = new ExecHandleShutdownHookAction(this);
        broadcast = new AsyncListenerBroadcast<ExecHandleListener>(ExecHandleListener.class, executor);
View Full Code Here

      throw new HibernateException( "Unable to initialize index: " + indexName, e );
    }
    configureOptimizerStrategy(searchFactoryImplementor, indexProps, this);
    configureIndexingParameters(searchFactoryImplementor, indexProps, this);
    if ( !searchFactoryImplementor.getLockableDirectoryProviders().containsKey( this ) ) {
      searchFactoryImplementor.getLockableDirectoryProviders().put( this, new ReentrantLock() );
    }
  }
View Full Code Here

      }
    }
    Set<DirectoryProvider> providers = searchFactoryImplementor.getLockableDirectoryProviders().keySet();
    perDirectoryProviderManipulationLocks = new HashMap<DirectoryProvider, Lock>( providers.size() );
    for (DirectoryProvider dp : providers) {
      perDirectoryProviderManipulationLocks.put( dp, new ReentrantLock() );
    }
    /***********hibernate search code**********
    perDirectoryProviderManipulationLocks = Collections.unmodifiableMap( perDirectoryProviderManipulationLocks );
    ******************************************/
  }
 
View Full Code Here

  }

  /****************add by Jerry*************/
  public void addLock(DirectoryProvider dp){
    if(perDirectoryProviderManipulationLocks.get(dp)==null)
    perDirectoryProviderManipulationLocks.put( dp, new ReentrantLock() );
  }
View Full Code Here

TOP

Related Classes of java.util.concurrent.locks.ReentrantLock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.