java 基础


public static void deleteDirectory(File directory) throws IOException {
if (!directory.exists()) {
return;
}
}

在VOID方法中可以用return;来退出函数


public static File createTempDir() {
File baseDir = new File(System.getProperty("java.io.tmpdir"));
String baseName = System.currentTimeMillis() + "-";

for (int counter = 0; counter < TEMP_DIR_ATTEMPTS; counter++) {
File tempDir = new File(baseDir, baseName + counter);
if (tempDir.mkdir()) {
return tempDir;
}
}
throw new IllegalStateException("Failed to create directory within "
+ TEMP_DIR_ATTEMPTS + " attempts (tried "
+ baseName + "0 to " + baseName + (TEMP_DIR_ATTEMPTS - 1) + ')');
}

不能正确return的直接抛异常


public static ClassLoader getDefaultClassLoader() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
}
catch (Throwable ex) {
// Cannot access thread context ClassLoader - falling back to system class loader...
}
if (cl == null) {
// No thread context class loader -> use class loader of this class.
cl = ClassUtils.class.getClassLoader();
}
return cl;
}

spring中的源代码 Thread.currentThread().getContextClassLoader();
[quote]
编译器加载类要依靠classloader, 而classloader有3个级别,从高到低分别是BootClassLoader(名字可能不准确) , ExtClassLoader, AppClassLoader.
这3个加载器分别对应着编译器去寻找类文件的优先级别和不同的路径:BootClassLoader对应jre/classes路径,是编译器最优先寻找class的地方
ExtClassLoader对应jre/lib/ext路径,是编译器次优先寻找class的地方
AppClassLoader对应当前路径,所以也是编译器默认找class的地方
现在给你分析你的问题我想因为Thread.currentThread().getContextClassLoader().loadClass(className)
是线程中的类加载器,直接调用起来效率最高,假设在这三个类加载器都找不到你的类,直接用Class.forname()映射
,这样就要多消耗资源了,一个线程调用资源开销不大,那要是几百个并发呢。
[/quote]


//Strip away the query part part if found
int index = requestURI.indexOf("?");
if (index != -1) {
requestURI = requestURI.substring(0, index);
}

去掉URI的参数部分


public static URI create(String str) {
try {
return new URI(str);
} catch (URISyntaxException x) {
IllegalArgumentException y = new IllegalArgumentException();
y.initCause(x);
throw y;
}
}

包装异常成为另外一种异常


for(;;){
System.out.println("11111");
}

无限循环


while(true){
...
if (flg){
break;
}
}

和for(;;)都是无限循环 效率上for要高点
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值