mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge pull request #6683 from hengyunab
* gh-6683: Test that LaunchedURLClassLoader works when thread is interrupted Ensure that LaunchedURLClassLoader works when thread is interrupted
This commit is contained in:
commit
9300c6d422
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2013 the original author or authors.
|
* Copyright 2012-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -244,17 +244,10 @@ public class RandomAccessDataFile implements RandomAccessData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RandomAccessFile acquire() throws IOException {
|
public RandomAccessFile acquire() throws IOException {
|
||||||
try {
|
this.available.acquireUninterruptibly();
|
||||||
this.available.acquire();
|
RandomAccessFile file = this.files.poll();
|
||||||
RandomAccessFile file = this.files.poll();
|
return (file == null
|
||||||
return (file == null
|
? new RandomAccessFile(RandomAccessDataFile.this.file, "r") : file);
|
||||||
? new RandomAccessFile(RandomAccessDataFile.this.file, "r")
|
|
||||||
: file);
|
|
||||||
}
|
|
||||||
catch (InterruptedException ex) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
throw new IOException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void release(RandomAccessFile file) {
|
public void release(RandomAccessFile file) {
|
||||||
@ -263,22 +256,16 @@ public class RandomAccessDataFile implements RandomAccessData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
|
this.available.acquireUninterruptibly(this.size);
|
||||||
try {
|
try {
|
||||||
this.available.acquire(this.size);
|
RandomAccessFile file = this.files.poll();
|
||||||
try {
|
while (file != null) {
|
||||||
RandomAccessFile file = this.files.poll();
|
file.close();
|
||||||
while (file != null) {
|
file = this.files.poll();
|
||||||
file.close();
|
|
||||||
file = this.files.poll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
this.available.release(this.size);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InterruptedException ex) {
|
finally {
|
||||||
Thread.currentThread().interrupt();
|
this.available.release(this.size);
|
||||||
throw new IOException(ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2014 the original author or authors.
|
* Copyright 2012-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -36,6 +36,7 @@ import static org.junit.Assert.assertTrue;
|
|||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
public class LaunchedURLClassLoaderTests {
|
public class LaunchedURLClassLoaderTests {
|
||||||
@ -101,4 +102,23 @@ public class LaunchedURLClassLoaderTests {
|
|||||||
assertThat(resource.openConnection().getInputStream().read(), equalTo(3));
|
assertThat(resource.openConnection().getInputStream().read(), equalTo(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void resolveFromNestedWhileThreadIsInterrupted() throws Exception {
|
||||||
|
File file = this.temporaryFolder.newFile();
|
||||||
|
TestJarCreator.createTestJar(file);
|
||||||
|
JarFile jarFile = new JarFile(file);
|
||||||
|
URL url = jarFile.getUrl();
|
||||||
|
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { url },
|
||||||
|
null);
|
||||||
|
try {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
URL resource = loader.getResource("nested.jar!/3.dat");
|
||||||
|
assertThat(resource.toString(), equalTo(url + "nested.jar!/3.dat"));
|
||||||
|
assertThat(resource.openConnection().getInputStream().read(), equalTo(3));
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Thread.interrupted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user