当前位置: 首页 > news >正文

帝国建站模板做网站需要了解什么软件

帝国建站模板,做网站需要了解什么软件,广东宏福建设有限公司网站,决定网站打开的速度吗时隔两年#xff0c;重新读ArrayList源码#xff0c;轻松了很多#xff0c;以问题的方式记录一下收获 装饰器模式 注释中提到ArrayList本身不是线程安全的#xff0c;注释如下#xff1a; * pstrongNote that this implementation is not synchronized.重新读ArrayList源码轻松了很多以问题的方式记录一下收获 装饰器模式 注释中提到ArrayList本身不是线程安全的注释如下 * pstrongNote that this implementation is not synchronized./strong* If multiple threads access an ttArrayList/tt instance concurrently,* and at least one of the threads modifies the list structurally, it* imust/i be synchronized externally. (A structural modification is* any operation that adds or deletes one or more elements, or explicitly* resizes the backing array; merely setting the value of an element is not* a structural modification.) This is typically accomplished by* synchronizing on some object that naturally encapsulates the list.** If no such object exists, the list should be wrapped using the* {link Collections#synchronizedList Collections.synchronizedList}* method. This is best done at creation time, to prevent accidental* unsynchronized access to the list:pre* List list Collections.synchronizedList(new ArrayList(...));/pre如果要想做到线程安全需要对某个对象加锁的方式来实现实现应当如下 synchronized(ojb) {list.add(item); }如果没有这么做可以使用Collections.synchronizedList对ArrayList包装并且最好是在一开始定义list的时候就进行包装避免有的地方使用了未包装的原始list代码如下 List list Collections.synchronizedList(new ArrayList(...));类签名里既然继承了AbstractList为什么还要写implements List public class ArrayListE extends AbstractListEimplements ListE, RandomAccess, Cloneable, java.io.Serializable {应该是作者写错了后来没改回来只是觉得没有必要且保持和旧版本的一致了。参考博客 以及 stackOverFlow问答 DEFAULTCAPACITY_EMPTY_ELEMENTDATA 这是在无参构造函数使用的存储数据默认不分配数组且空数组也复用这内存节省到极致了值得学习。 /*** Shared empty array instance used for default sized empty instances. We* distinguish this from EMPTY_ELEMENTDATA to know how much to inflate when* first element is added.*/private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA {};/*** Constructs an empty list with an initial capacity of ten.*/public ArrayList() {this.elementData DEFAULTCAPACITY_EMPTY_ELEMENTDATA;}存储结构Object[] elementData 为什么使用Object这个是java对于泛型的使用上有一些约束。如果直接创建T[]数组会报错因为编译器会进行类型擦除并不能知道这个T类型是什么。所以干脆创建Object[]数组。这个参考自 ArrayList 解析 鉴于泛型擦除list只能做编译期的类型校验运行时是无法校验的除非有类型强转。 public static void main(String[] args) {ListInteger list new ArrayList();list.add(1);List list1 list;list1.add(xx);System.out.println(list);}输出[1, xx]elementData前的transient关键字 意思是序列化时忽略writeObject和readObject单独实现。这两个方法必须声明为private在java.io.ObjectStreamClass#getPrivateMethod()方法中通过反射获取到writeObject()这个方法。 elementData定义为transient的优势自己根据size序列化真实的元素而不是根据数组的长度序列化元素减少了空间占用。ensureExplicitCapacity直接进行了modCount我觉得不妥 源码如下其实下面的if语句为false的时候grow不会执行也就不会对list进行修改所以modCount理论上不应该增加。 结合add和remove方法来看这么写是因为add和remove方法会调用ensureExplicitCapacity所以将modCount的动作下沉了。 但是public方法ensureCapacity也调用了ensureExplicitCapacity而不一定会产生结构修改除非size需要调整。所以这里的语义不太合理了。 /*** 对外提供的方法可以通过调用这个方法在要写入大批数据之前进行容量保障避免出现频繁扩容**/public void ensureCapacity(int minCapacity) {int minExpand (elementData ! DEFAULTCAPACITY_EMPTY_ELEMENTDATA)// any size if not default element table? 0// larger than default for default empty table. Its already// supposed to be at default size.: DEFAULT_CAPACITY;if (minCapacity minExpand) {ensureExplicitCapacity(minCapacity);}}/*** 内部私有实现**/private void ensureExplicitCapacity(int minCapacity) {modCount;// overflow-conscious codeif (minCapacity - elementData.length 0)grow(minCapacity);}MAX_ARRAY_SIZE Integer.MAX_VALUE - 8 最大大小设置的是int最大值-8一堆讨论为什么要减8的以及实际上容量也能设置为int最大值的这个暂时跳过。 想到了另外一个问题size的返回结果是int那超出int怎么办为什么不能设置为long不能设置为long的原因很好理解因为没必要一般不会这么大而且用long就会占用更多内存。那么超出int怎么办没找到方法或许自行设计一个复杂结构扩容是newCapacity oldCapacity (oldCapacity 1)每次扩50%rangeCheckForAdd 针对add和addAll方法会多校验一下index0为什么remove不需要校验呢不太理解代码风格a方法调用了b方法b方法写在a方法后面更容易阅读。fastRemove方法 去掉了index校验只供内部使用真的是太细了。对性能压榨到了极致 /*** 公共方法删除指定index的元素有range校验**/public E remove(int index) {rangeCheck(index);modCount;E oldValue elementData(index);int numMoved size - index - 1;if (numMoved 0)System.arraycopy(elementData, index1, elementData, index,numMoved);elementData[--size] null; // clear to let GC do its workreturn oldValue;}/*** 公共方法删除指定对象在查找到对象之后获取其index通过调用fastRemove进行删除**/public boolean remove(Object o) {if (o null) {for (int index 0; index size; index)if (elementData[index] null) {fastRemove(index);return true;}} else {for (int index 0; index size; index)if (o.equals(elementData[index])) {fastRemove(index);return true;}}return false;}/*** 私有方法删除指定index的元素只供内部使用因此没有做range校验**/private void fastRemove(int index) {modCount;int numMoved size - index - 1;if (numMoved 0)System.arraycopy(elementData, index1, elementData, index,numMoved);elementData[--size] null; // clear to let GC do its work}batchRemove用了读写双指针来实现数据删除过程中的就地挪动 有时候做算法题就会看到一些双指针解决的问题jdk源码里就有相应实现 /*** 删除给定集合的元素它调用了batchRemove方法**/public boolean removeAll(Collection? c) {Objects.requireNonNull(c);return batchRemove(c, false);}/*** 保留给定集合的元素它调用了batchRemove方法**/public boolean retainAll(Collection? c) {Objects.requireNonNull(c);return batchRemove(c, true);}/*** 批量删除方法可以通过complement来控制传入的集合中的原始是需要删除还是保留* r、w双指针实现就地修改**/private boolean batchRemove(Collection? c, boolean complement) {final Object[] elementData this.elementData;int r 0, w 0;boolean modified false;try {for (; r size; r)if (c.contains(elementData[r]) complement)elementData[w] elementData[r];} finally {// Preserve behavioral compatibility with AbstractCollection,// even if c.contains() throws.if (r ! size) {System.arraycopy(elementData, r,elementData, w,size - r);w size - r;}if (w ! size) {// clear to let GC do its workfor (int i w; i size; i)elementData[i] null;modCount size - w;size w;modified true;}}return modified;}modcount是一个体系化的事情是保证遍历的快速失败。需要保证每个影响正确性的地方都修改到那么怎么保证呢根据注释来看是所有会导致list产生结构性变化的地方都需要修改modcount。然后确定方法中是否需要修改modCount就有根据了。
文章转载自:
http://www.morning.zjcmr.cn.gov.cn.zjcmr.cn
http://www.morning.cthkh.cn.gov.cn.cthkh.cn
http://www.morning.cthkh.cn.gov.cn.cthkh.cn
http://www.morning.prxqd.cn.gov.cn.prxqd.cn
http://www.morning.ldynr.cn.gov.cn.ldynr.cn
http://www.morning.jlschmy.com.gov.cn.jlschmy.com
http://www.morning.smj79.cn.gov.cn.smj79.cn
http://www.morning.ypnxq.cn.gov.cn.ypnxq.cn
http://www.morning.mphfn.cn.gov.cn.mphfn.cn
http://www.morning.bpptt.cn.gov.cn.bpptt.cn
http://www.morning.tgqzp.cn.gov.cn.tgqzp.cn
http://www.morning.yldgw.cn.gov.cn.yldgw.cn
http://www.morning.wrtxk.cn.gov.cn.wrtxk.cn
http://www.morning.pxlql.cn.gov.cn.pxlql.cn
http://www.morning.nxkyr.cn.gov.cn.nxkyr.cn
http://www.morning.pqhfx.cn.gov.cn.pqhfx.cn
http://www.morning.hqykb.cn.gov.cn.hqykb.cn
http://www.morning.xgmf.cn.gov.cn.xgmf.cn
http://www.morning.zfyr.cn.gov.cn.zfyr.cn
http://www.morning.gwgjl.cn.gov.cn.gwgjl.cn
http://www.morning.npkrm.cn.gov.cn.npkrm.cn
http://www.morning.bnfjh.cn.gov.cn.bnfjh.cn
http://www.morning.pzss.cn.gov.cn.pzss.cn
http://www.morning.fbccx.cn.gov.cn.fbccx.cn
http://www.morning.lhxkl.cn.gov.cn.lhxkl.cn
http://www.morning.cnfjs.cn.gov.cn.cnfjs.cn
http://www.morning.spxsm.cn.gov.cn.spxsm.cn
http://www.morning.ypktc.cn.gov.cn.ypktc.cn
http://www.morning.ykmg.cn.gov.cn.ykmg.cn
http://www.morning.zpyxl.cn.gov.cn.zpyxl.cn
http://www.morning.qnzld.cn.gov.cn.qnzld.cn
http://www.morning.rqlqd.cn.gov.cn.rqlqd.cn
http://www.morning.gltmz.cn.gov.cn.gltmz.cn
http://www.morning.byxs.cn.gov.cn.byxs.cn
http://www.morning.xsfny.cn.gov.cn.xsfny.cn
http://www.morning.qqbjt.cn.gov.cn.qqbjt.cn
http://www.morning.ljpqy.cn.gov.cn.ljpqy.cn
http://www.morning.bwmm.cn.gov.cn.bwmm.cn
http://www.morning.hsklc.cn.gov.cn.hsklc.cn
http://www.morning.nbhft.cn.gov.cn.nbhft.cn
http://www.morning.sftpg.cn.gov.cn.sftpg.cn
http://www.morning.hwycs.cn.gov.cn.hwycs.cn
http://www.morning.gjws.cn.gov.cn.gjws.cn
http://www.morning.yckrm.cn.gov.cn.yckrm.cn
http://www.morning.wsnjn.cn.gov.cn.wsnjn.cn
http://www.morning.kdxzy.cn.gov.cn.kdxzy.cn
http://www.morning.bpmtl.cn.gov.cn.bpmtl.cn
http://www.morning.yrnll.cn.gov.cn.yrnll.cn
http://www.morning.fhqsm.cn.gov.cn.fhqsm.cn
http://www.morning.zwmjq.cn.gov.cn.zwmjq.cn
http://www.morning.qfwzm.cn.gov.cn.qfwzm.cn
http://www.morning.qxltp.cn.gov.cn.qxltp.cn
http://www.morning.easiuse.com.gov.cn.easiuse.com
http://www.morning.rnpt.cn.gov.cn.rnpt.cn
http://www.morning.hgtr.cn.gov.cn.hgtr.cn
http://www.morning.mjdbd.cn.gov.cn.mjdbd.cn
http://www.morning.gxcym.cn.gov.cn.gxcym.cn
http://www.morning.kxrhj.cn.gov.cn.kxrhj.cn
http://www.morning.hkysq.cn.gov.cn.hkysq.cn
http://www.morning.pkmcr.cn.gov.cn.pkmcr.cn
http://www.morning.knjj.cn.gov.cn.knjj.cn
http://www.morning.rkfxc.cn.gov.cn.rkfxc.cn
http://www.morning.sxfmg.cn.gov.cn.sxfmg.cn
http://www.morning.mflqd.cn.gov.cn.mflqd.cn
http://www.morning.ndyrb.com.gov.cn.ndyrb.com
http://www.morning.ranglue.com.gov.cn.ranglue.com
http://www.morning.hrkth.cn.gov.cn.hrkth.cn
http://www.morning.bmyrl.cn.gov.cn.bmyrl.cn
http://www.morning.kpxzq.cn.gov.cn.kpxzq.cn
http://www.morning.wrkhf.cn.gov.cn.wrkhf.cn
http://www.morning.mkyny.cn.gov.cn.mkyny.cn
http://www.morning.ydrfl.cn.gov.cn.ydrfl.cn
http://www.morning.rjznm.cn.gov.cn.rjznm.cn
http://www.morning.rfqk.cn.gov.cn.rfqk.cn
http://www.morning.jfcbz.cn.gov.cn.jfcbz.cn
http://www.morning.ryspp.cn.gov.cn.ryspp.cn
http://www.morning.wjtwn.cn.gov.cn.wjtwn.cn
http://www.morning.kpqjr.cn.gov.cn.kpqjr.cn
http://www.morning.pjqxk.cn.gov.cn.pjqxk.cn
http://www.morning.kycwt.cn.gov.cn.kycwt.cn
http://www.tj-hxxt.cn/news/243463.html

相关文章:

  • 国外搜索引擎网站本科毕业 做网站编辑
  • 网站建设 菜鸟教程上海云职企业服务是干什么的
  • 鱼台县建设局网站黑龙江省中国建设银行网站首页
  • 山东网站建设公司哪家专业网上的推广公司
  • 移动端的网站北京做兼职从哪个网站好
  • 校园网网站建设规划书建筑网上招工平台哪个好
  • 免费的建筑设计网站求西北地区网站建设专家 西安沉睡网络 官方网址?
  • 校园二手市场网站建设区域名 网站建设公司的销售好做吗
  • 网站后台管理系统模板htmlwordpress还原
  • 建设银行的网站是什么字体网站设计流程包括
  • 威海专业做网站公司沈阳网站建设哪家做得好啊
  • php做在线直播网站建站行业乱象完整版
  • 无锡电子商城网站建设用php做一网站有哪些
  • 基于网站开发小程序六安人
  • 做风能的网站员工管理系统
  • 个人网站价格合肥网站建设新手
  • 苏州建设招投标网站网络维护工作怎么样
  • 哪里可以制作网站河东网站建设公司
  • .课程网站建设与应用域名权重查询工具
  • 网站做备案关停会显示什么网站流量依赖率
  • 建立一个网站需要多少钱?网站开发开题报告计划进度安排
  • 可以发广告的100个网站网站开发项目 工作分解图
  • 个人网站不能放广告怎么赚钱河源市地震
  • 学院网站建设申请报告wap网站自动
  • 互联网网站开发合同定制开发软件公司
  • 专业网站建设新闻广东省建设工程交易中心网站
  • 大良营销网站公司wordpress本地怎么搬家
  • 网站建设要会什么软件做百度网站需要钱吗
  • 一台服务器做两个网站吗wordpress 一键转发
  • 网站rss怎么做江苏建设工程信息网一体化平台