/**
  * Set whether the receiver's {@link #dequeue(long)} method should return query operations.
  *
  * @param processQueries <code>true</code> if the receiver's {@link #dequeue(long)} method should
  *     return query operations or <code>false</code> if query operations should be queued but not
  *     returned by the receiver's {@link #dequeue(long)} method until this method is called with a
  *     value of <code>true</code>.
  */
 public void setProcessQueries(boolean processQueries) {
   synchronized (nonQueryOperations) {
     if (this.processQueries != processQueries) {
       this.processQueries = processQueries;
       if (processQueries && !queryOperations.isEmpty()) {
         nonQueryOperations.notifyAll();
       }
     }
   }
 }
  /** Removes a connection */
  void removeItem(ManagedPoolItem item, ManagedConnection mConn) {
    synchronized (_connectionPool) {
      _idlePool.remove(mConn);

      _connectionPool.remove(item);
      _connectionPool.notifyAll();
    }

    try {
      item.destroy();
    } catch (Exception e) {
      log.log(Level.WARNING, e.toString(), e);
    }
  }
  public void end() {
    done = true;

    printStatistics();
    this.interrupt();

    synchronized (workerThreads) {
      workToDo.clear();
      workerThreads.notifyAll();
    }

    for (int i = 0; i < workerThreads.size(); i++) {
      ((WorkerThread) workerThreads.get(i)).done();
    }
  }
 /**
  * Add the given operation to the tail of this queue.
  *
  * @param operation the operation to be added to the queue
  */
 public void enqueue(IndexOperation operation) {
   synchronized (nonQueryOperations) {
     if (operation instanceof RemoveResourceOperation) {
       Resource resource = ((RemoveResourceOperation) operation).getResource();
       for (int i = nonQueryOperations.size() - 1; i >= 0; i--) {
         if (nonQueryOperations.get(i).removeWhenResourceRemoved(resource)) {
           nonQueryOperations.remove(i);
         }
       }
       for (int i = queryOperations.size() - 1; i >= 0; i--) {
         if (queryOperations.get(i).removeWhenResourceRemoved(resource)) {
           queryOperations.remove(i);
         }
       }
     }
     if (operation.isQuery()) {
       queryOperations.add(operation);
     } else {
       nonQueryOperations.add(operation);
     }
     nonQueryOperations.notifyAll();
   }
 }
  // Reads a single packet from the connection, adding it to the packet
  // queue when a complete packet is ready.
  private void _readOnePacket() throws IOException {
    byte[] data = null;

    // Read in the packet
    int length = _inStream.readInt();
    if (length < 11) {
      throw new IOException("JDWP packet length < 11 (" + length + ")");
    }

    data = new byte[length];
    data[0] = (byte) (length >>> 24);
    data[1] = (byte) (length >>> 16);
    data[2] = (byte) (length >>> 8);
    data[3] = (byte) length;
    _inStream.readFully(data, 4, length - 4);

    JdwpPacket packet = JdwpPacket.fromBytes(data);
    if (packet != null) {
      synchronized (_commandQueue) {
        _commandQueue.add(packet);
        _commandQueue.notifyAll();
      }
    }
  }
Example #6
1
  public static void main(String args[]) throws Exception {
    is_64_bit_system = (Platform.is64bit());

    OutputAnalyzer output;
    whiteBox = WhiteBox.getWhiteBox();

    // Grab my own PID
    String pid = Integer.toString(ProcessTools.getProcessId());
    ProcessBuilder pb = new ProcessBuilder();

    AllocThread[] alloc_threads = new AllocThread[256];
    ReleaseThread[] release_threads = new ReleaseThread[64];

    int index;
    // Create many allocation threads
    for (index = 0; index < alloc_threads.length; index++) {
      alloc_threads[index] = new AllocThread();
    }

    // Fewer release threads
    for (index = 0; index < release_threads.length; index++) {
      release_threads[index] = new ReleaseThread();
    }

    if (is_64_bit_system()) {
      sleep_wait(2 * 60 * 1000);
    } else {
      sleep_wait(60 * 1000);
    }
    // pause the stress test
    phase = TestPhase.pause;
    while (pause_count.intValue() < alloc_threads.length + release_threads.length) {
      sleep_wait(10);
    }

    long mallocd_total_in_KB = (mallocd_total + K / 2) / K;

    // Now check if the result from NMT matches the total memory allocated.
    String expected_test_summary =
        "Test (reserved=" + mallocd_total_in_KB + "KB, committed=" + mallocd_total_in_KB + "KB)";
    // Run 'jcmd <pid> VM.native_memory summary'
    pb.command(new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
    output = new OutputAnalyzer(pb.start());
    output.shouldContain(expected_test_summary);

    // Release all allocated memory
    phase = TestPhase.release;
    synchronized (mallocd_memory) {
      mallocd_memory.notifyAll();
    }

    // Join all threads
    for (index = 0; index < alloc_threads.length; index++) {
      try {
        alloc_threads[index].join();
      } catch (InterruptedException e) {
      }
    }

    for (index = 0; index < release_threads.length; index++) {
      try {
        release_threads[index].join();
      } catch (InterruptedException e) {
      }
    }

    // All test memory allocated should be released
    output = new OutputAnalyzer(pb.start());
    output.shouldNotContain("Test (reserved=");

    // Verify that tracking level has not been downgraded
    pb.command(
        new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"});
    output = new OutputAnalyzer(pb.start());
    output.shouldNotContain("Tracking level has been downgraded due to lack of resources");
  }