Cool catch => Use simple data structure, with fine performance
impact. :-)
Peter
Am 24.03.2006 um 13:37 schrieb [EMAIL PROTECTED]:
Author: remm
Date: Fri Mar 24 04:37:27 2006
New Revision: 388500
URL: http://svn.apache.org/viewcvs?rev=388500&view=rev
Log:
- As suggested by Peter, replace the (synced) Stack with a
specialized unsynced stack.
Modified:
tomcat/connectors/trunk/util/java/org/apache/tomcat/util/net/
AprEndpoint.java
Modified: tomcat/connectors/trunk/util/java/org/apache/tomcat/util/
net/AprEndpoint.java
URL: http://svn.apache.org/viewcvs/tomcat/connectors/trunk/util/
java/org/apache/tomcat/util/net/AprEndpoint.java?
rev=388500&r1=388499&r2=388500&view=diff
======================================================================
========
--- tomcat/connectors/trunk/util/java/org/apache/tomcat/util/net/
AprEndpoint.java (original)
+++ tomcat/connectors/trunk/util/java/org/apache/tomcat/util/net/
AprEndpoint.java Fri Mar 24 04:37:27 2006
@@ -19,7 +19,6 @@
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Stack;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -109,10 +108,9 @@
/**
- * Available processors.
+ * Available workers.
*/
- // FIXME: Stack is synced, which makes it a non optimal choice
- protected Stack workers = new Stack();
+ protected WorkerStack workers = null;
/**
@@ -510,7 +508,7 @@
if (initialized)
return;
-
+
// Create the root APR memory pool
rootPool = Pool.create(0);
// Create the pool for the server socket
@@ -625,6 +623,9 @@
running = true;
paused = false;
+ // Create worker collection
+ workers = new WorkerStack(maxThreads);
+
// Start acceptor thread
acceptorThread = new Thread(new Acceptor(), getName()
+ "-Acceptor");
acceptorThread.setPriority(threadPriority);
@@ -808,7 +809,7 @@
synchronized (workers) {
if (workers.size() > 0) {
curThreadsBusy++;
- return ((Worker) workers.pop());
+ return (workers.pop());
}
if ((maxThreads > 0) && (curThreads < maxThreads)) {
curThreadsBusy++;
@@ -1516,5 +1517,60 @@
public boolean process(long socket);
}
+
+ // -------------------------------------------------
WorkerStack Inner Class
+
+
+ public class WorkerStack {
+
+ protected Worker[] workers = null;
+ protected int end = 0;
+
+ public WorkerStack(int size) {
+ workers = new Worker[size];
+ }
+
+ /**
+ * Put the object into the queue.
+ *
+ * @param object the object to be appended to the
queue (first element).
+ */
+ public void push(Worker worker) {
+ workers[end++] = worker;
+ }
+
+ /**
+ * Get the first object out of the queue. Return null if
the queue
+ * is empty.
+ */
+ public Worker pop() {
+ if (end > 0) {
+ return workers[--end];
+ }
+ return null;
+ }
+
+ /**
+ * Get the first object out of the queue, Return null if
the queue
+ * is empty.
+ */
+ public Worker peek() {
+ return workers[end];
+ }
+
+ /**
+ * Is the queue empty?
+ */
+ public boolean isEmpty() {
+ return (end == 0);
+ }
+
+ /**
+ * How many elements are there in this queue?
+ */
+ public int size() {
+ return (end);
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]