Я пытаюсь найти правильный способ настроить код обработки исключений для устранения проблем с производительностью.
вот номер, который я получил.
По сути, я хочу настроить его на обработку вызова исключений для внутренних веб-служб.
Любые комментарии о том, дает ли один способ лучшую производительность по сравнению с другим, и почему будут оценены.
спасибо ..
Я опубликовал несколько раз для трех различных структур кодирования в Java
Try time Existing Code Structure throw same exception in catch block:12632
Try timeestimatedTimeTryThrowsChild Exception inCatchBlock: 1579
Try timeestimatedTimeTryReturnNullAfter Catch Block: 1579
Try time Existing Code Structure throw same exception in catch block:16580
Try timeestimatedTimeTryThrowsChild Exception inCatchBlock: 2368
Try timeestimatedTimeTryReturnNullAfter Catch Block: 4737
Try time Existing Code Structure throw same exception in catch block:29211
Try timeestimatedTimeTryThrowsChild Exception inCatchBlock: 3947
Try timeestimatedTimeTryReturnNullAfter Catch Block: 2369
Try time Existing Code Structure throw same exception in catch block:9869
Try timeestimatedTimeTryThrowsChild Exception inCatchBlock: 1974
Try timeestimatedTimeTryReturnNullAfter Catch Block: 1579
Try time Existing Code Structure throw same exception in catch block:13422
Try timeestimatedTimeTryThrowsChild Exception inCatchBlock: 1579
Try timeestimatedTimeTryReturnNullAfter Catch Block: 1579
Try time Existing Code Structure throw same exception in catch block:9474
Try timeestimatedTimeTryThrowsChild Exception inCatchBlock: 1579
Try timeestimatedTimeTryReturnNullAfter Catch Block: 1973
Try time Existing Code Structure throw same exception in catch block:5922
Try timeestimatedTimeTryThrowsChild Exception inCatchBlock: 789
Try timeestimatedTimeTryReturnNullAfter Catch Block: 789
public class Overhead {
public static void main(String[] args) {
String testString = "";
long startTimeTry = System.nanoTime();
tryTrimThrowSameException(testString);
long estimatedTimeTry = System.nanoTime() - startTimeTry;
long startTimeIf = System.nanoTime();
ifTrim(testString);
long estimatedTimeIf = System.nanoTime() - startTimeIf;
long startTimeTryThrowsinCatchBlock = System.nanoTime();
tryTrimThrowsChildExceptioninCatchBlock(testString);
long estimatedTimeTryThrowsinCatchBlock = System.nanoTime() - startTimeTryThrowsinCatchBlock;
long startTimeTryReturnNull = System.nanoTime();
tryTrimReturnNull(testString);
long estimatedTimeTryReturnNull = System.nanoTime() - startTimeTryReturnNull;
System.out.println("Try time Existing Code Structure throw same exception in catch block:" + estimatedTimeTry);
//System.out.println("If time:" + estimatedTimeIf);
System.out.println("Try timeestimatedTimeTryThrowsChild Exception inCatchBlock: " + estimatedTimeTryThrowsinCatchBlock);
System.out.println("Try timeestimatedTimeTryReturnNullAfter Catch Block: " + estimatedTimeTryReturnNull);
}
public static String tryTrimThrowSameException(String raw) {
try {
return raw.trim();
}
catch (java.lang.Exception e ) {
//throw new java.lang.NullPointerException() ;
System.out.println("throws an exception") ;
throw e ;
}
//return null;
}
public static String tryTrimThrowsChildExceptioninCatchBlock(String raw) {
try {
return raw.trim();
}
catch (java.lang.Exception e ) {
System.out.println("throws an exception") ;
throw new java.lang.NullPointerException() ;
//throw e ;
}
// return null;
}
public static String tryTrimReturnNull(String raw) {
try {
return raw.trim();
}
catch (java.lang.Exception e ) {
//throw new java.lang.NullPointerException() ;
System.out.println("throws an exception") ;
//throw e ;
}
return null;
}
public static String ifTrim(String raw) {
if (raw == null) {
return null;
}
return raw.trim();
}
}