`
freish
  • 浏览: 82950 次
  • 性别: Icon_minigender_1
  • 来自: 摄影帝国
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
js引擎
Nashorn
Rhino
与java类库冲突的解决——endorsed java
jdk的lib或者jdk/jre目录下加入endorsed文件夹,把冲突的jar放入endorsed文件夹中
可以通过System.getProperty("java.endorsed.dirs"); 来查看endorsed目录的具体位置。
threadlocal性能历史 threadlocal http://hi.baidu.com/henvy/blog/item/66f847ca166a4081c81768f6.html
ThreadLocal 的性能

虽然线程局部变量早已赫赫有名并被包括 Posix pthreads 规范在内的很多线程框架支持,但最初的 Java 线程设计中却省略了它,只是在 Java 平台的版本 1.2 中才添加上去。在很多方面, ThreadLocal 仍在发展之中;在版本 1.3 中它被重写,版本 1.4 中又重写了一次,两次都专门是为了性能问题。

在 JDK 1.2 中, ThreadLocal 的实现方式与清单 2 中的方式非常相似,除了用同步 WeakHashMap 代替 HashMap 来存储 values 之外。(以一些额外的性能开销为代价,使用 WeakHashMap 解决了无法对 Thread 对象进行垃圾回收的问题。)不用说, ThreadLocal 的性能是相当差的。

Java 平台版本 1.3 提供的 ThreadLocal 版本已经尽量更好了;它不使用任何同步,从而不存在可伸缩性问题,而且它也不使用弱引用。相反地,人们通过给 Thread 添加一个实例变量(该变量用于保存当前线程的从线程局部变量到它的值的映射的 HashMap )来修改 Thread 类以支持 ThreadLocal 。因为检索或设置一个线程局部变量的过程不涉及对可能被另一个线程读写的数据的读写操作,所以您可以不用任何同步就实现 ThreadLocal.get() 和 set() 。而且,因为每线程值的引用被存储在自已的 Thread 对象中,所以当对 Thread 进行垃圾回收时,也能对该 Thread 的每线程值进行垃圾回收。

不幸的是,即使有了这些改进,Java 1.3 中的 ThreadLocal 的性能仍然出奇地慢。据我的粗略测量,在双处理器 Linux 系统上的 Sun 1.3 JDK 中进行 ThreadLocal.get() 操作,所耗费的时间大约是无争用同步的两倍。性能这么差的原因是 Thread.currentThread() 方法的花费非常大,占了 ThreadLocal.get() 运行时间的三分之二还多。虽然有这些缺点,JDK 1.3 ThreadLocal.get() 仍然比争用同步快得多,所以如果在任何存在严重争用的地方(可能是有非常多的线程,或者同步块被频繁地执行,或者同步块很大), ThreadLocal 可能仍然要高效得多。

在 Java 平台的最新版本,即版本 1.4b2 中, ThreadLocal 和 Thread.currentThread() 的性能都有了很大提高。有了这些提高, ThreadLocal 应该比其它技术,如用池,更快。由于它比其它技术更简单,也更不易出错,人们最终将发现它是避免线程间出现不希望的交互的有效途径。
ZipEntry,ZipFile,ZipInputStream解压zip文件 zip, 解压
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

public class ZipUtil {
	public static void decompression(File zipPath, File dpath) throws Exception {
		if (zipPath == null) {
			throw new IllegalArgumentException("zipFile cannot be null");
		}
		if (!zipPath.isFile() && zipPath.exists()) {
			throw new Exception("指定路径是目录或文件不存在:" + zipPath.getAbsolutePath());
		}

		String zipFileName = zipPath.getName();
		if (zipFileName.toLowerCase().endsWith(".zip")) {
			int nameLength = zipFileName.length();
			zipFileName = zipFileName.substring(0, nameLength - 4);
		}

		if (dpath == null) {
			dpath = new File(zipFileName);
		} else {
			dpath = new File(dpath, zipFileName);
		}

		if (dpath.exists()) {
			System.out.println("目录已经存在:" + dpath.getAbsolutePath());
		} else {
			dpath.mkdirs();
		}

		ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(
				zipPath));
		try {
			ZipEntry entry = null;
			ZipFile zipFile = new ZipFile(zipPath);
			byte[] cache = new byte[8096];
			while ((entry = zipInputStream.getNextEntry()) != null) {
				String fileName = entry.getName();
				if (entry.isDirectory()) {
					new File(dpath, fileName).mkdirs();
					continue;
				}

				InputStream inputStream = zipFile.getInputStream(entry);
				OutputStream ops = null;
				try {
					// 创建文件,写文件
					File tmpFile = new File(dpath, fileName);
					tmpFile.createNewFile();

					ops = new FileOutputStream(tmpFile);

					int length = -1;
					while ((length = inputStream.read(cache)) != -1) {
						ops.write(cache, 0, length);
						ops.flush();
					}
				} finally {
					if (inputStream != null) {
						inputStream.close();
					}

					if (ops != null) {
						ops.close();
					}
					zipInputStream.closeEntry();
				}
			}
		} finally {
			zipInputStream.close();
		}
	}
}
查看oracle表之间的约束关系 oracle
select * from user_constraints
Global site tag (gtag.js) - Google Analytics