java杂谈

时间:2019-04-15
本文章向大家介绍java杂谈,主要包括java杂谈使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

https://blog.csdn.net/qq_34337272/article/details/80012284

concurrenthashmap 分成N个hashtable 默认16 每个hashtable 加锁
hashmap是线程不安全的
ThreadPoolExecutor.AbortPolicy()-Always throws RejectedExecutionException.*直接抛异常
ThreadPoolExecutor.CallerRunsPolicy() -Executes task r in the caller’s thread, unless the executor has been shut down, in which case the task is discarded.*主线程执行 即调用线程执行
ThreadPoolExecutor.DiscardOldestPolicy() -Obtains and ignores the next task that the executor would otherwise execute, if one is immediately available,and then retries execution of task r, unless the executor is shut down, in which case task r is instead discarded.*丢弃队列中最早的任务,知道新的任务挤进队列
ThreadPoolExecutor.DiscardPolicy() -Does nothing, which has the effect of discarding task r.*直接丢弃

war 和 warexploded

war模式:将WEB工程以包的形式上传到服务器 ;
war exploded模式:将WEB工程以当前文件夹的位置关系上传到服务器;

(1)war模式这种可以称之为是发布模式,看名字也知道,这是先打成war包,再发布;
(2)war exploded模式是直接把文件夹、jsp页面 、classes等等移到Tomcat 部署文件夹里面,进行加载部署。因此这种方式支持热部署,一般在开发的时候也是用这种方式。
(3)在平时开发的时候,使用热部署的话,应该对Tomcat进行相应的设置,这样的话修改的jsp界面什么的东西才可以及时的显示出来。

list的深度拷贝

克隆方法1:利用原list作为参数直接构造方法生成。
克隆方法2:手动遍历将原listString0中的元素全部添加到复制表中。
克隆方法3:调用Collections的静态工具方法 Collections.copy
以上方法再list的元素为基础类型时候是没有问题的,但是一旦存放的是对象类型,咋不能实现深度拷贝,因为存的是对象的地址,只是拷贝出一个新的对象,指向原来的地址。
真的深度拷贝:可以转为流,然后再转回去。

@SuppressWarnings("unchecked")
public static <T> List<T> deepCopyList(List<T> dest, List<T> src) throws IOException, ClassNotFoundException {
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(byteOut);
    out.writeObject(src);
    ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
    ObjectInputStream in = new ObjectInputStream(byteIn);
    dest = (List<T>) in.readObject();
    return dest;
}
待续。。。。