Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
64e8b1d4
Commit
64e8b1d4
authored
Aug 16, 2019
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Add properties for Jetty threadpool"
See gh-17871
parent
1024d747
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
42 deletions
+18
-42
ServerProperties.java
...ingframework/boot/autoconfigure/web/ServerProperties.java
+2
-2
JettyWebServerFactoryCustomizer.java
...nfigure/web/embedded/JettyWebServerFactoryCustomizer.java
+7
-24
JettyWebServerFactoryCustomizerTests.java
...re/web/embedded/JettyWebServerFactoryCustomizerTests.java
+9
-16
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java
View file @
64e8b1d4
...
...
@@ -907,12 +907,12 @@ public class ServerProperties {
private
Integer
selectors
=
-
1
;
/**
* Maximum
amount
of threads.
* Maximum
number
of threads.
*/
private
Integer
maxThreads
=
200
;
/**
* Minimum
amount
of threads.
* Minimum
number
of threads.
*/
private
Integer
minThreads
=
8
;
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java
View file @
64e8b1d4
...
...
@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.web.embedded;
import
java.time.Duration
;
import
java.util.Arrays
;
import
java.util.function.Consumer
;
import
org.eclipse.jetty.server.AbstractConnector
;
import
org.eclipse.jetty.server.ConnectionFactory
;
...
...
@@ -82,11 +83,11 @@ public class JettyWebServerFactoryCustomizer
propertyMapper
.
from
(
jettyProperties:
:
getMaxHttpPostSize
).
asInt
(
DataSize:
:
toBytes
).
when
(
this
::
isPositive
)
.
to
((
maxHttpPostSize
)
->
customizeMaxHttpPostSize
(
factory
,
maxHttpPostSize
));
propertyMapper
.
from
(
jettyProperties:
:
getMaxThreads
).
when
(
this
::
isPositive
)
.
to
((
maxThreads
)
->
customize
MaxThreads
(
factory
,
maxThreads
));
.
to
((
maxThreads
)
->
customize
ThreadPool
(
factory
,
(
threadPool
)
->
threadPool
.
setMaxThreads
(
maxThreads
)
));
propertyMapper
.
from
(
jettyProperties:
:
getMinThreads
).
when
(
this
::
isPositive
)
.
to
((
minThreads
)
->
customize
MinThreads
(
factory
,
minThreads
));
propertyMapper
.
from
(
jettyProperties:
:
getIdleTimeout
).
when
(
this
::
isPositive
)
.
to
((
idleTimeout
)
->
customizeIdleTimeout
(
factory
,
idleTimeout
));
.
to
((
minThreads
)
->
customize
ThreadPool
(
factory
,
(
threadPool
)
->
threadPool
.
setMinThreads
(
minThreads
)
));
propertyMapper
.
from
(
jettyProperties:
:
getIdleTimeout
).
when
(
this
::
isPositive
)
.
to
(
(
idleTimeout
)
->
customizeThreadPool
(
factory
,
(
threadPool
)
->
threadPool
.
setIdleTimeout
(
idleTimeout
)
));
propertyMapper
.
from
(
properties:
:
getConnectionTimeout
).
whenNonNull
()
.
to
((
connectionTimeout
)
->
customizeConnectionTimeout
(
factory
,
connectionTimeout
));
propertyMapper
.
from
(
jettyProperties:
:
getAccesslog
).
when
(
ServerProperties
.
Jetty
.
Accesslog
::
isEnabled
)
...
...
@@ -140,29 +141,11 @@ public class JettyWebServerFactoryCustomizer
});
}
private
void
customize
MaxThreads
(
ConfigurableJettyWebServerFactory
factory
,
int
maxThreads
)
{
private
void
customize
ThreadPool
(
ConfigurableJettyWebServerFactory
factory
,
Consumer
<
QueuedThreadPool
>
customizer
)
{
factory
.
addServerCustomizers
((
connector
)
->
{
ThreadPool
threadPool
=
connector
.
getThreadPool
();
if
(
threadPool
instanceof
QueuedThreadPool
)
{
((
QueuedThreadPool
)
threadPool
).
setMaxThreads
(
maxThreads
);
}
});
}
private
void
customizeMinThreads
(
ConfigurableJettyWebServerFactory
factory
,
int
minThreads
)
{
factory
.
addServerCustomizers
((
connector
)
->
{
ThreadPool
threadPool
=
connector
.
getThreadPool
();
if
(
threadPool
instanceof
QueuedThreadPool
)
{
((
QueuedThreadPool
)
threadPool
).
setMinThreads
(
minThreads
);
}
});
}
private
void
customizeIdleTimeout
(
ConfigurableJettyWebServerFactory
factory
,
int
idleTimeout
)
{
factory
.
addServerCustomizers
((
connector
)
->
{
ThreadPool
threadPool
=
connector
.
getThreadPool
();
if
(
threadPool
instanceof
QueuedThreadPool
)
{
((
QueuedThreadPool
)
threadPool
).
setIdleTimeout
(
idleTimeout
);
customizer
.
accept
((
QueuedThreadPool
)
threadPool
);
}
});
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java
View file @
64e8b1d4
...
...
@@ -28,7 +28,6 @@ import org.eclipse.jetty.server.HttpConfiguration.ConnectionFactory;
import
org.eclipse.jetty.server.RequestLog
;
import
org.eclipse.jetty.server.RequestLogWriter
;
import
org.eclipse.jetty.util.thread.QueuedThreadPool
;
import
org.eclipse.jetty.util.thread.ThreadPool
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -116,33 +115,27 @@ class JettyWebServerFactoryCustomizerTests {
}
@Test
void
maxThreadsCanBeCustomized
()
throws
IOException
{
void
maxThreadsCanBeCustomized
()
{
bind
(
"server.jetty.max-threads=100"
);
JettyWebServer
server
=
customizeAndGetServer
();
ThreadPool
threadPool
=
server
.
getServer
().
getThreadPool
();
if
(
threadPool
instanceof
QueuedThreadPool
)
{
assertThat
(((
QueuedThreadPool
)
threadPool
).
getMaxThreads
()).
isEqualTo
(
100
);
}
QueuedThreadPool
threadPool
=
(
QueuedThreadPool
)
server
.
getServer
().
getThreadPool
();
assertThat
(
threadPool
.
getMaxThreads
()).
isEqualTo
(
100
);
}
@Test
void
minThreadsCanBeCustomized
()
throws
IOException
{
void
minThreadsCanBeCustomized
()
{
bind
(
"server.jetty.min-threads=100"
);
JettyWebServer
server
=
customizeAndGetServer
();
ThreadPool
threadPool
=
server
.
getServer
().
getThreadPool
();
if
(
threadPool
instanceof
QueuedThreadPool
)
{
assertThat
(((
QueuedThreadPool
)
threadPool
).
getMinThreads
()).
isEqualTo
(
100
);
}
QueuedThreadPool
threadPool
=
(
QueuedThreadPool
)
server
.
getServer
().
getThreadPool
();
assertThat
(
threadPool
.
getMinThreads
()).
isEqualTo
(
100
);
}
@Test
void
idleTimeoutCanBeCustomized
()
throws
IOException
{
void
idleTimeoutCanBeCustomized
()
{
bind
(
"server.jetty.idle-timeout=100"
);
JettyWebServer
server
=
customizeAndGetServer
();
ThreadPool
threadPool
=
server
.
getServer
().
getThreadPool
();
if
(
threadPool
instanceof
QueuedThreadPool
)
{
assertThat
(((
QueuedThreadPool
)
threadPool
).
getIdleTimeout
()).
isEqualTo
(
100
);
}
QueuedThreadPool
threadPool
=
(
QueuedThreadPool
)
server
.
getServer
().
getThreadPool
();
assertThat
(
threadPool
.
getIdleTimeout
()).
isEqualTo
(
100
);
}
private
CustomRequestLog
getRequestLog
(
JettyWebServer
server
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment