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
77cbab79
Commit
77cbab79
authored
Oct 17, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make TomcatEmbeddedWebappClassLoader parallel capable
Closes gh-10477
parent
027c5a0e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
12 deletions
+18
-12
TomcatEmbeddedWebappClassLoader.java
.../web/embedded/tomcat/TomcatEmbeddedWebappClassLoader.java
+16
-10
TomcatEmbeddedWebappClassLoaderTests.java
...embedded/tomcat/TomcatEmbeddedWebappClassLoaderTests.java
+2
-2
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatEmbeddedWebappClassLoader.java
View file @
77cbab79
...
@@ -21,24 +21,28 @@ import java.net.URL;
...
@@ -21,24 +21,28 @@ import java.net.URL;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Enumeration
;
import
java.util.Enumeration
;
import
org.apache.catalina.loader.WebappClassLoader
;
import
org.apache.catalina.loader.
Parallel
WebappClassLoader
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.logging.LogFactory
;
/**
/**
* Extension of Tomcat's {@link WebappClassLoader} that does not consider the
* Extension of Tomcat's {@link
Parallel
WebappClassLoader} that does not consider the
* {@link ClassLoader#getSystemClassLoader() system classloader}. This is required to
* {@link ClassLoader#getSystemClassLoader() system classloader}. This is required to
* ensure that any custom context classloader is always used (as is the case with some
* ensure that any custom context class
loader is always used (as is the case with some
* executable archives).
* executable archives).
*
*
* @author Phillip Webb
* @author Phillip Webb
* @since 2.0.0
* @since 2.0.0
*/
*/
public
class
TomcatEmbeddedWebappClassLoader
extends
WebappClassLoader
{
public
class
TomcatEmbeddedWebappClassLoader
extends
Parallel
WebappClassLoader
{
private
static
final
Log
logger
=
LogFactory
private
static
final
Log
logger
=
LogFactory
.
getLog
(
TomcatEmbeddedWebappClassLoader
.
class
);
.
getLog
(
TomcatEmbeddedWebappClassLoader
.
class
);
static
{
ClassLoader
.
registerAsParallelCapable
();
}
public
TomcatEmbeddedWebappClassLoader
()
{
public
TomcatEmbeddedWebappClassLoader
()
{
super
();
super
();
}
}
...
@@ -58,14 +62,16 @@ public class TomcatEmbeddedWebappClassLoader extends WebappClassLoader {
...
@@ -58,14 +62,16 @@ public class TomcatEmbeddedWebappClassLoader extends WebappClassLoader {
}
}
@Override
@Override
public
synchronized
Class
<?>
loadClass
(
String
name
,
boolean
resolve
)
public
Class
<?>
loadClass
(
String
name
,
boolean
resolve
)
throws
ClassNotFoundException
{
throws
ClassNotFoundException
{
Class
<?>
result
=
findExistingLoadedClass
(
name
);
synchronized
(
getClassLoadingLock
(
name
))
{
result
=
(
result
==
null
?
doLoadClass
(
name
)
:
result
);
Class
<?>
result
=
findExistingLoadedClass
(
name
);
if
(
result
==
null
)
{
result
=
(
result
==
null
?
doLoadClass
(
name
)
:
result
);
throw
new
ClassNotFoundException
(
name
);
if
(
result
==
null
)
{
throw
new
ClassNotFoundException
(
name
);
}
return
resolveIfNecessary
(
result
,
resolve
);
}
}
return
resolveIfNecessary
(
result
,
resolve
);
}
}
private
Class
<?>
findExistingLoadedClass
(
String
name
)
{
private
Class
<?>
findExistingLoadedClass
(
String
name
)
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatEmbeddedWebappClassLoaderTests.java
View file @
77cbab79
...
@@ -28,7 +28,7 @@ import java.util.jar.JarOutputStream;
...
@@ -28,7 +28,7 @@ import java.util.jar.JarOutputStream;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipEntry
;
import
org.apache.catalina.core.StandardContext
;
import
org.apache.catalina.core.StandardContext
;
import
org.apache.catalina.loader.WebappClassLoader
;
import
org.apache.catalina.loader.
Parallel
WebappClassLoader
;
import
org.apache.catalina.webresources.StandardRoot
;
import
org.apache.catalina.webresources.StandardRoot
;
import
org.apache.catalina.webresources.WarResourceSet
;
import
org.apache.catalina.webresources.WarResourceSet
;
import
org.junit.Rule
;
import
org.junit.Rule
;
...
@@ -73,7 +73,7 @@ public class TomcatEmbeddedWebappClassLoaderTests {
...
@@ -73,7 +73,7 @@ public class TomcatEmbeddedWebappClassLoaderTests {
throws
Exception
{
throws
Exception
{
URLClassLoader
parent
=
new
URLClassLoader
(
URLClassLoader
parent
=
new
URLClassLoader
(
new
URL
[]
{
new
URL
(
webInfClassesUrlString
(
war
))
},
null
);
new
URL
[]
{
new
URL
(
webInfClassesUrlString
(
war
))
},
null
);
try
(
WebappClassLoader
classLoader
=
new
TomcatEmbeddedWebappClassLoader
(
try
(
Parallel
WebappClassLoader
classLoader
=
new
TomcatEmbeddedWebappClassLoader
(
parent
))
{
parent
))
{
StandardContext
context
=
new
StandardContext
();
StandardContext
context
=
new
StandardContext
();
context
.
setName
(
"test"
);
context
.
setName
(
"test"
);
...
...
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