如果jar应用程序由于某种原因崩溃,我希望它生成一个包含错误的崩溃日志文本文件。
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
String filename = "./"+sdf.format(cal.getTime())+".txt";
PrintStream writer;
try {
writer = new PrintStream(filename, "UTF-8");
writer.println(e.getClass() + ": " + e.getMessage());
for (int i = 0; i < e.getStackTrace().length; i++) {
writer.println(e.getStackTrace()[i].toString());
}
} catch (FileNotFoundException | UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
public static List<Pair<Double, Vector3>> calcAttackPosition() {
// --八个方向
List<Pair<Double, Vector3>> indexList = new ArrayList<Pair<Double, Vector3>>();
int depth = 1;
int curDepth = 0;
int index = 0;
Vector3 v;
Vector3 right = GameConstants.NORMALIZE_RIGHT;
while (curDepth < depth) {
curDepth += 1;
int endIdx = curDepth;
int startIdx = -curDepth;
for (int i = startIdx; i< endIdx; i++) {
LogUtil.debug("下横=" + "(" + i + "," + (-endIdx) + ")");
LogUtil.info("AngleBetween=" + AngleBetween(new Vector3(i, 0.0, -endIdx), new Vector3(1, 0, 0)));
LogUtil.debug("上横=" + "(" + (-i) + "," + endIdx + ")");
LogUtil.info("AngleBetween=" + AngleBetween(new Vector3(-i, 0.0, endIdx), new Vector3(1, 0, 0)));
LogUtil.debug("右竖=" + "(" + endIdx + "," + i + ")");
LogUtil.info("AngleBetween=" + AngleBetween(new Vector3(endIdx, 0.0, i), new Vector3(1, 0, 0)));
LogUtil.debug("左竖=" + "(" + (-endIdx) + "," + (-i) + ")");
LogUtil.info("AngleBetween=" + AngleBetween(new Vector3(-endIdx, 0.0, -i), new Vector3(1, 0, 0)));
v = new Vector3(i, 0.0, -endIdx);
indexList.add(new Pair<Double, Vector3>(AngleBetween(v, right), v));
v = new Vector3(-i, 0.0, endIdx);
indexList.add(new Pair<Double, Vector3>(AngleBetween(v, right), v));
v = new Vector3(endIdx, 0.0, i);
indexList.add(new Pair<Double, Vector3>(AngleBetween(v, right), v));
v = new Vector3(-endIdx, 0.0, -i);
indexList.add(new Pair<Double, Vector3>(AngleBetween(v, right), v));
}
}
Collections.sort(indexList, new AttackPairValueComparator());
return indexList;
}
public static double AngleBetween(Vector3 vector1, Vector3 vector2)
{
double sin = vector1.x * vector2.z - vector2.x * vector1.z;
double cos = vector1.x * vector2.x + vector1.z * vector2.z;
return Math.atan2(sin, cos) * (180 / Math.PI);
}
catch (Throwable throwable){
MailUtil.sendMail("Thrwoable " + throwable.getClass(), throwable.getStackTrace());
}
Queue<String> queue = new LinkedList<String>();
queue.offer("a");
queue.poll(); // 返回第一个元素,并在队列中删除
queue.peek(); // 返回第一个元素
brew tap adoptopenjdk/openjdk
brew install --cask adoptopenjdk16
export:
# JDK 8
export JAVA_HOME_8=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
export JAVA_HOME_11=/Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
export JAVA_HOME_16=/Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home
export JAVA_HOME_17=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
export PATH=$PATH:$JAVA_HOME_16
alias jdk8="export JAVA_HOME=$JAVA_HOME_8"
alias jdk11="export JAVA_HOME=$JAVA_HOME_11"
alias jdk16="export JAVA_HOME=$JAVA_HOME_16"
alias jdk17="export JAVA_HOME=$JAVA_HOME_17"
export JAVA_HOME=$JAVA_HOME_16
####