我想从我自己的服务器上下载一个大的.jar文件。 (https://luis.team) 我在那里做了一个线程下载它,因为它非常大。 这是我的下载代码:
public Update(String version, File outputFile) {
URL url;
URLConnection connection = null;
try {
url = new URL("https://raw.githubusercontent.com/Luuuuuis/InstantVerify/master/version");
connection = url.openConnection();
} catch (IOException e1) {
e1.printStackTrace();
}
assert connection != null;
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String[] versionCode = in.readLine().split("&&");
if (!(versionCode[0].equalsIgnoreCase(version))) {
/*
* Download from URL given in version file
*/
if(versionCode[1] != null && !versionCode[1].equalsIgnoreCase("null")) {
Thread th = new Thread(() -> {
try {
URL downloadURL = new URL(versionCode[1]);
URLConnection urlConnection = downloadURL.openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");
InputStream inputStream = urlConnection.getInputStream();
OutputStream outputStream = new FileOutputStream(outputFile);
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
InstantVerify.version += " (outdated)";
} catch (Exception ex) {
ex.printStackTrace();
}
});
th.start();
}
} else {
InstantVerify.version += " (latest)";
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
此后,我得到了一个很小的文件(大约30MB)和一个Java运行时错误:
A fatal error has been detected by the Java Runtime Environment:
SIGBUS (0x7) at pc=0x00007f8fd9b5ed10, pid=14021, tid=0x00007f8fa5b56700
JRE version: Java(TM) SE Runtime Environment (8.0_201-b09) (build 1.8.0_201-
b09)
Java VM: Java HotSpot(TM) 64-Bit Server VM (25.201-b09 mixed mode linux-
amd64 compressed oops)
Problematic frame:
C [libzip.so+0x11d10] newEntry.isra.4+0x60
Failed to write core dump. Core dumps have been disabled. To enable core
dumping, try "ulimit -c unlimited" before starting Java again
An error report file with more information is saved as:
/home/ServerTest/Bungee/hs_err_pid14021.log
Compiled method (nm) 6767 201 n 0
java.util.zip.ZipFile::getEntry (native)
total in heap [0x00007f8fc517a510,0x00007f8fc517a868] = 856
relocation [0x00007f8fc517a638,0x00007f8fc517a678] = 64
main code [0x00007f8fc517a680,0x00007f8fc517a868] = 488
If you would like to submit a bug report, please visit:
http://bugreport.java.com/bugreport/crash.jsp
The crash happened outside the Java Virtual Machine in native code.
See problematic frame for where to report the bug.
Aborted
我想Java中的内存映射有问题,因为我的根服务器只有2GB的RAM。 我该怎么做才能解决此问题?谢谢。
答案 0 :(得分:3)
SIGBUS错误是操作系统抛出的未对齐数据错误。从根本上讲,这意味着服务器所在平台的数据未正确对齐。例如,某些Unix系统坚持认为所有数据都在8字节边界上对齐。似乎文件已成功下载,并且它是对导致崩溃的java.util.zip.ZipFile :: getEntry的调用。如果您在该平台上启用了核心转储,那么Java开发人员应该能够确定该错误是在初始zip文件的构建中还是在读取zip文件中。
答案 1 :(得分:0)
我通过解决方法解决了此问题。
URL downloadURL = new URL(versionCode[1]);
HttpURLConnection urlConnection = (HttpURLConnection) downloadURL.openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");
InputStream inputStream = urlConnection.getInputStream();
Files.copy(inputStream, outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
inputStream.close();