Merged branch 'jetty-9.2.x' into branch 'master'.

This commit is contained in:
Simone Bordet 2014-11-27 12:01:02 +01:00
commit 007b7dac1c
4 changed files with 69 additions and 35 deletions

View File

@ -72,6 +72,7 @@ import org.eclipse.jetty.util.resource.ResourceFactory;
/* ------------------------------------------------------------ */
/** The default servlet.
*
* This servlet, normally mapped to /, provides the handling for static
* content, OPTION and TRACE methods for the context.
* The following initParameters are supported, these can be set either
@ -126,7 +127,8 @@ import org.eclipse.jetty.util.resource.ResourceFactory;
* If set to true, it will use mapped file buffer to serve static content
* when using NIO connector. Setting this value to false means that
* a direct buffer will be used instead of a mapped file buffer.
* By default, this is set to true.
* This is set to false by default by this class, but may be overridden
* by eg webdefault.xml
*
* cacheControl If set, all static content will have this value set as the cache-control
* header.

View File

@ -31,7 +31,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.eclipse.jetty.util.BlockingArrayQueue;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.annotation.ManagedOperation;
@ -39,6 +38,7 @@ import org.eclipse.jetty.util.annotation.Name;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool;
@ -90,9 +90,11 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
setStopTimeout(5000);
if (queue==null)
queue=new BlockingArrayQueue<>(_minThreads, _minThreads);
{
int capacity=Math.max(_minThreads, 8);
queue=new BlockingArrayQueue<>(capacity, capacity);
}
_jobs=queue;
}
@Override
@ -165,7 +167,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
StringBuilder dmp = new StringBuilder();
for (StackTraceElement element : unstopped.getStackTrace())
{
dmp.append(StringUtil.__LINE_SEPARATOR).append("\tat ").append(element);
dmp.append(System.lineSeparator()).append("\tat ").append(element);
}
LOG.warn("Couldn't stop {}{}", unstopped, dmp.toString());
}
@ -359,6 +361,12 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
LOG.warn("{} rejected {}", this, job);
throw new RejectedExecutionException(job.toString());
}
else
{
// Make sure there is at least one thread executing the job.
if (getThreads() == 0)
startThreads(1);
}
}
/**
@ -429,14 +437,13 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
thread.start();
started = true;
--threadsToStart;
}
finally
{
if (!started)
_threadsStarted.decrementAndGet();
}
if (started)
threadsToStart--;
}
return true;
}
@ -446,7 +453,6 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
return new Thread(runnable);
}
@Override
@ManagedOperation("dump thread state")
public String dump()
@ -481,8 +487,8 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
{
out.append(String.valueOf(thread.getId())).append(' ').append(thread.getName()).append(' ').append(thread.getState().toString()).append(idle ? " IDLE" : "");
if (thread.getPriority()!=Thread.NORM_PRIORITY)
out.append(" prio="+thread.getPriority());
out.append('\n');
out.append(" prio=").append(String.valueOf(thread.getPriority()));
out.append(System.lineSeparator());
if (!idle)
ContainerLifeCycle.dump(out, indent, Arrays.asList(trace));
}
@ -666,14 +672,13 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
if (thread.getId() == id)
{
StringBuilder buf = new StringBuilder();
buf.append(thread.getId()).append(" ").append(thread.getName()).append(" ").append(thread.getState()).append(":\n");
buf.append(thread.getId()).append(" ").append(thread.getName()).append(" ");
buf.append(thread.getState()).append(":").append(System.lineSeparator());
for (StackTraceElement element : thread.getStackTrace())
buf.append(" at ").append(element.toString()).append('\n');
buf.append(" at ").append(element.toString()).append(System.lineSeparator());
return buf.toString();
}
}
return null;
}
}

View File

@ -18,11 +18,6 @@
package org.eclipse.jetty.util.thread;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@ -31,11 +26,15 @@ import org.eclipse.jetty.toolchain.test.AdvancedRunner;
import org.eclipse.jetty.toolchain.test.annotation.Slow;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.StdErrLog;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@RunWith(AdvancedRunner.class)
public class QueuedThreadPoolTest
{
@ -288,4 +287,25 @@ public class QueuedThreadPoolTest
((StdErrLog)Log.getLogger(QueuedThreadPool.class)).setHideStacks(false);
}
}
@Test
public void testZeroMinThreads() throws Exception
{
int maxThreads = 10;
int minThreads = 0;
QueuedThreadPool pool = new QueuedThreadPool(maxThreads, minThreads);
pool.start();
final CountDownLatch latch = new CountDownLatch(1);
pool.execute(new Runnable()
{
@Override
public void run()
{
latch.countDown();
}
});
assertTrue(latch.await(5, TimeUnit.SECONDS));
}
}

View File

@ -11,17 +11,17 @@
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- The intent of this descriptor is to include jetty specific or common -->
<!-- configuration for all webapps. If a context has a webdefault.xml -->
<!-- descriptor, it is applied before the contexts own web.xml file -->
<!-- descriptor, it is applied before the context's own web.xml file -->
<!-- -->
<!-- A context may be assigned a default descriptor by: -->
<!-- + Calling WebApplicationContext.setDefaultsDescriptor -->
<!-- + Passed an arg to addWebApplications -->
<!-- A context may be assigned a default descriptor by calling -->
<!-- WebAppContext.setDefaultsDescriptor(String). -->
<!-- -->
<!-- This file is used both as the resource within the jetty.jar (which is -->
<!-- used as the default if no explicit defaults descriptor is set) and it -->
<!-- is copied to the etc directory of the Jetty distro and explicitly -->
<!-- by the jetty.xml file. -->
<!-- This file is present in the jetty-webapp.jar, and is used as the -->
<!-- defaults descriptor if no other is explicitly set on a context. -->
<!-- -->
<!-- A copy of this file is also placed into the $JETTY_HOME/etc dir of -->
<!-- the distribution, and is referenced by some of the other xml files, -->
<!-- eg the jetty-deploy.xml file. -->
<!-- ===================================================================== -->
<description>
@ -119,18 +119,16 @@
* maxCachedFiles The maximum number of files to cache
*
* useFileMappedBuffer
* If set to true, it will use mapped file buffer to serve static content
* when using NIO connector. Setting this value to false means that
* If set to true, it will use mapped file buffers to serve static content
* when using an NIO connector. Setting this value to false means that
* a direct buffer will be used instead of a mapped file buffer.
* By default, this is set to true.
* This file sets the value to true.
*
* cacheControl If set, all static content will have this value set as the cache-control
* header.
*
-->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
@ -323,6 +321,8 @@
<!-- ==================================================================== -->
<!-- Default session configuration -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
@ -330,7 +330,7 @@
<!-- ==================================================================== -->
<!-- Default MIME mappings -->
<!-- The default MIME mappings are provided by the mime.properties -->
<!-- resource in the org.eclipse.jetty.server.jar file. Additional or modified -->
<!-- resource in the jetty-http.jar file. Additional or modified -->
<!-- mappings may be specified here -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- UNCOMMENT TO ACTIVATE
@ -341,6 +341,8 @@
-->
<!-- ==================================================================== -->
<!-- Default welcome files -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
@ -348,6 +350,8 @@
</welcome-file-list>
<!-- ==================================================================== -->
<!-- Default locale encodings -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<locale-encoding-mapping-list>
<locale-encoding-mapping>
<locale>ar</locale>
@ -507,6 +511,9 @@
</locale-encoding-mapping>
</locale-encoding-mapping-list>
<!-- ==================================================================== -->
<!-- Disable TRACE method with security constraint -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<security-constraint>
<web-resource-collection>
<web-resource-name>Disable TRACE</web-resource-name>