Examples of Semaphore


Examples of EDU.oswego.cs.dl.util.concurrent.Semaphore

            drm.registerListener("HASingleton", listener);
            drm.add("HASingleton", "HASingleton");           
         }
        
         // Create a semaphore to gate the threads and acquire all its permits
         Semaphore semaphore = new Semaphore(count + 1);
         for (int i = 0; i <= count; i++)
            semaphore.acquire();
        
         DeployerThread[] deployers = new DeployerThread[keys.length];
         for (int i = 0; i < count; i++)
         {
            DistributedReplicantManager.ReplicantListener listener = null;
            if (conflicting)
            {
               listener = new MockHASingletonDeployer(deployer, keys[i], log);
            }
            else
            {
               listener = new NullListener();
            }
            deployers[i] = new DeployerThread(deployer, keys[i], listener, semaphore, log);
            deployers[i].start();
         }
        
         String[] jgKeys = keys;
         if (!conflicting)
         {
            // The JGroups thread also deals with the MockHASingletonDeployer
            // key that the DeployerThreads don't
            jgKeys = new String[keys.length + 1];
            System.arraycopy(keys, 0, jgKeys, 0, keys.length);
            jgKeys[keys.length] = "HASingleton";           
         }
         JGroupsThread jgThread = new JGroupsThread(drm, jgKeys, remote.getName(), semaphore);
         jgThread.start();
        
         // Launch the threads
         semaphore.release(count + 1);
        
         boolean reacquired = false;
         try
         {
            // Give the threads 5 secs to acquire the semaphore
            long maxElapsed = System.currentTimeMillis() + 5000;
            for (int i = 0; i < keys.length; i++)
            {
               if (deployers[i].getCount() < 0)
               {
                  assertTrue("Thread " + keys[i] + " started in time",
                              maxElapsed - System.currentTimeMillis() > 0);
                  sleepThread(10);
                  i--; // try again
               }  
            }
           
            while (jgThread.getCount() < 0)
            {
               assertTrue("jgThread started in time",
                           maxElapsed - System.currentTimeMillis() > 0);
               sleepThread(10);              
            }
            // Reaquire all the permits, thus showing the threads didn't deadlock
           
            // Give them 500 ms per loop
            maxElapsed = System.currentTimeMillis() + (500 * LOOP_COUNT);
            for (int i = 0; i <= count; i++)
            {
               long waitTime = maxElapsed - System.currentTimeMillis();
               assertTrue("Acquired thread " + i, semaphore.attempt(waitTime));
            }
           
            reacquired = true;
           
            // Ensure there were no exceptions
View Full Code Here

Examples of Package.Entities.Semaphore

         return NumberAttribute;
     }
    
     public void runfile(String file) throws IOException {
        br = util.getBufferTextLines(file);
        semaphoreofattribute = new Semaphore();
        while ((line = br.readLine()) != null) {searchListAttribute();}
    }
View Full Code Here

Examples of com.antlersoft.util.Semaphore

        freePageOffset=0;
        freePage=null;
        pageLRU=new int[ENTRY_PAGE_CACHE_SIZE];
        pageLRU[0]=0;
        lruSize=1;
        pageFlushLock=new Semaphore();
        deleteLock=new Semaphore();
    }
View Full Code Here

Examples of com.arjuna.ats.txoj.semaphore.Semaphore

/*      */     {
/*  987 */       this.systemKey = type();
/*      */
/*  989 */       if (this.mutex == null)
/*      */       {
/*  991 */         this.mutex = new Semaphore(this.systemKey);
/*      */       }
/*      */
/*  994 */       if (this.mutex != null)
/*      */       {
/*  996 */         if (this.mutex.lock() == 0)
View Full Code Here

Examples of com.intellij.util.concurrency.Semaphore

                                    final @Nullable XExpression xExpression) {
    final String evalText = xExpression == null ? null : xExpression.getExpression();
    if (topFrame == null || StringUtil.isEmptyOrSpaces(evalText)) return null;

    final Ref<String> evalResult = new Ref<String>();
    final Semaphore semaphore = new Semaphore();
    semaphore.down();

    try {
      myDebugProcess.getVmConnection().evaluateOnCallFrame(isolate, topFrame, evalText, new VmCallback<VmValue>() {
        public void handleResult(final VmResult<VmValue> result) {
          final VmValue vmValue = result.getResult();
          if (vmValue != null) {
            evalResult.set(vmValue.getText());
          }
          semaphore.up();
        }
      });
    }
    catch (IOException e) {/**/}

    semaphore.waitFor(1000);
    return evalResult.get();
  }
View Full Code Here

Examples of com.nexirius.util.Semaphore

     * @return the output stream packed into a byte array
     * @throws Exception
     */
    public byte[] resolve(HTMLSessionVariable sessionVariable, DataModel model, InputStream in, boolean isEditor)
            throws Exception {
        Semaphore semaphore = new Semaphore();
        PipedInputStream in1 = new PipedInputStream();
        PipedOutputStream out1 = new PipedOutputStream(in1);
        PipedInputStream in2 = new PipedInputStream();
        PipedOutputStream out2 = new PipedOutputStream(in2);
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        VariableStore oldValues = null;

        PushbackInputStream inParser = null;

        if (observerStream == null) {
            inParser = new PushbackInputStream(in2);
        } else {
            inParser = new PushbackInputStream(new InObserver(in2));
        }

        if (model != null) {
            oldValues = new VariableStore();

            variableStore.setVariable(VariableStore.FULLNAME, getModelStackAsString(model));
            DataModelVariableHandler.setVariablesFor(model, variableStore, oldValues, translator);
        }

// replace variables first
        new PrecompilerThread(in, out1);
        VariableResolverThread vr = new VariableResolverThread(new PushbackInputStream(in1), out2);
        HTMLParserThread parser = new HTMLParserThread(sessionVariable, model, isEditor, inParser, out, semaphore);

        semaphore.waitFor();

        if (vr.getException() != null) {

            throw vr.getException();
        }
View Full Code Here

Examples of com.sun.cldc.util.Semaphore

    /**
     * Initialize shared objects.
     * @throws IllegalStateException if already initialized.
     */
    public static void init() {
        semReady = new Semaphore(0);
        semContinue = new Semaphore(0);
        init0(semReady, semContinue);
    }
View Full Code Here

Examples of data.Semaphore

  public static void main(String[] args) {

    JFrame window = new JFrame();
    DrawSemaphore panel = new DrawSemaphore();
   
    Semaphore semaphore = new Semaphore();
    semaphore.addObserver(panel);
   
    JButton button = new JButton("Placebo");
    button.setLocation(20, 200);
    button.addActionListener(new ButtonEventHandler(semaphore));
    panel.add(button);
View Full Code Here

Examples of edu.emory.mathcs.backport.java.util.concurrent.Semaphore

    public void testPerformance() throws Exception {
       
        System.out.println("Running Benchmark for destination="+destination+", producers="+PRODUCER_COUNT+", consumers="+CONSUMER_COUNT+", deliveryMode="+deliveryMode);
        final int CONSUME_COUNT = destination.isTopic() ? CONSUMER_COUNT*PRODUCE_COUNT : PRODUCE_COUNT;

        final Semaphore consumersStarted = new Semaphore(1-(CONSUMER_COUNT));        
        final Semaphore producersFinished = new Semaphore(1-(PRODUCER_COUNT));
        final Semaphore consumersFinished = new Semaphore(1-(CONSUMER_COUNT));        
        final ProgressPrinter printer = new ProgressPrinter(PRODUCE_COUNT+CONSUME_COUNT, 10);
       
        // Start a producer and consumer
   
        profilerPause("Benchmark ready.  Start profiler ");
       
        long start = System.currentTimeMillis();
       
       
        final AtomicInteger receiveCounter = new AtomicInteger(0);
        for( int i=0; i < CONSUMER_COUNT; i++) {
            new Thread() {
                public void run() {
                    try {
                       
                        // Consume the messages    
                        StubConnection connection = new StubConnection(broker);
                        ConnectionInfo connectionInfo = createConnectionInfo();
                        connection.send(connectionInfo);

                        SessionInfo sessionInfo = createSessionInfo(connectionInfo);
                        ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
                        consumerInfo.setPrefetchSize(1000);
                        connection.send(sessionInfo);
                        connection.send(consumerInfo);
                       
                        consumersStarted.release();
                       
                        while( receiveCounter.get() < CONSUME_COUNT ) {
               
                            int counter=0;
                            // Get a least 1 message.
                            Message msg = receiveMessage(connection, 2000);
                            if( msg!=null ) {
                                printer.increment();
                                receiveCounter.incrementAndGet();
                               
                                counter++;
                               
                                // Try to piggy back a few extra message acks if they are ready.
                                Message extra=null;
                                while( (extra = receiveMessage(connection,0))!=null ) {
                                    msg=extra;
                                    printer.increment();
                                    receiveCounter.incrementAndGet();
                                    counter++;
                                }
                            }
                           
                           
                            if(msg!=null) {
                                connection.send(createAck(consumerInfo, msg, counter, MessageAck.STANDARD_ACK_TYPE));
                            } else if ( receiveCounter.get() < CONSUME_COUNT )  {
                                System.out.println("Consumer stall, waiting for message #"+receiveCounter.get()+1);
                            }
                        }
                       
                        connection.send(closeConsumerInfo(consumerInfo));                       
                    } catch (Throwable e) {
                        e.printStackTrace();
                    } finally {
                        consumersFinished.release();               
                    }
                }

            }.start();
        }
       
        // Make sure that the consumers are started first to avoid sending messages
        // before a topic is subscribed so that those messages are not missed.
        consumersStarted.acquire();
       
        // Send the messages in an async thread.
        for( int i=0; i < PRODUCER_COUNT; i++) {
            new Thread() {
                public void run() {
                    try {
                        StubConnection connection = new StubConnection(broker);
                        ConnectionInfo connectionInfo = createConnectionInfo();
                        connection.send(connectionInfo);
                       
                        SessionInfo sessionInfo = createSessionInfo(connectionInfo);
                        ProducerInfo producerInfo = createProducerInfo(sessionInfo);
                        connection.send(sessionInfo);
                        connection.send(producerInfo);
   
                        for(int i=0; i < PRODUCE_COUNT/PRODUCER_COUNT; i++) {
                            Message message = createMessage(producerInfo, destination);
                            message.setPersistent(deliveryMode);
                            message.setResponseRequired(false);
                            connection.send(message);
                            printer.increment();
                        }
                    } catch (Throwable e) {
                        e.printStackTrace();
                    } finally {
                        producersFinished.release();               
                    }
                };
            }.start();
        }
       
        producersFinished.acquire();
        long end1 = System.currentTimeMillis();
        consumersFinished.acquire();
        long end2 = System.currentTimeMillis();
       
        System.out.println("Results for destination="+destination+", producers="+PRODUCER_COUNT+", consumers="+CONSUMER_COUNT+", deliveryMode="+deliveryMode);
        System.out.println("Produced at messages/sec: "+ (PRODUCE_COUNT*1000.0/(end1-start)));
        System.out.println("Consumed at messages/sec: "+ (CONSUME_COUNT*1000.0/(end2-start)));       
View Full Code Here

Examples of evolaris.framework.database.datamodel.Semaphore

   * @param session to be used by business methods within this transaction
   * @param accessedGroupId ID of group to be locked; null => all groups are locked
   */
  private static void lockSemaphore(Session session,Long accessedGroupId){
    // TODO create and update group-specific locking single entries in an extended semaphore table on demand
    Semaphore semaphore = (Semaphore) session.load(Semaphore.class, 1L, LockMode.UPGRADE);
    semaphore.setEditedAt(new Date(System.currentTimeMillis()));
    session.save(semaphore);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.