1 为什么说arraylist比vector 快?(除线程安全不安全问题) 2 在mybatis 和 hibernate 两者里面, 它们各自有什么东西 是对方实现不了的? |
|
![]() 10分 |
第一个看了源码,都是通过数组实现的,get、add方法除了synchronized,似乎没有啥其它区别,难道是指其它方法实现方面?
第二个,确实没怎么系统思考过,找到一篇博文:http://blog.csdn.net/firejuly/article/details/8190229 |
![]() |
你应聘的什么职位?mybatis和hibenate和游戏开发有什么关系?
|
![]() |
1.扩容
2.mb的sql配置化,,hb的hql |
![]() |
大家看看:ArrayList与Vector的线程保险
http://www.myexception.cn/program/1045146.html 我不明白 那个 null 为何有时 出来 有时候不出来 import java.util.ArrayList; import java.util.Vector; /** * Copyright(c), 2011-2100 * <p>Cwc System * @description:Synchronized of Vector and ArrayList * @file name: com.cwc.util.SynchronizedCollection.java * @create: by author axis on Mar 2, 2011 5:53:52 PM * @since: JDK1.6u21 */ public class SynchronizedCollection { @SuppressWarnings("unchecked") static ArrayList arrayList = new ArrayList(20); @SuppressWarnings("unchecked") static Vector vector = new Vector(); public static void main(String[] args) { Thread threadOne = new Thread(){ @SuppressWarnings("unchecked") public void run(){ for (int i = 0; i < 10; i++) { arrayList.add(arrayList.size(),new Integer(i)); vector.add(vector.size(),new Integer(i)); try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } } } }; Thread threadTwo= new Thread(){ @SuppressWarnings("unchecked") public void run(){ for (int i = 0; i < 10; i++) { arrayList.add(arrayList.size(),new Integer(i)); vector.add(vector.size(),new Integer(i)); try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } } } }; try { threadOne.start(); threadTwo.start(); threadOne.join(); threadTwo.join(); System.out.println(arrayList); System.out.println(vector); } catch (InterruptedException e) { e.printStackTrace(); } } } [0, 0, 1, 1, 2, null, 3, 3, 4, 4, 5, 5, 6, 6, 7, null, 8, 8, 9, 9] [0, 1, 2, 3, 3, 4, null, 5, 6, 6, 7, 7, 8, 8, 9, 9] i < size ?? |
![]() |
arraylist和vector都是集合类,但是一个是线程安全的,一个是不安全的
|
![]() |
vector是枚举过时的方法,为线程同步,因此方法里面都加了sysn同步锁,每次运行代码都要访问这个锁,里面是否有内容在执行,若有程序停止,若没有,继续运行。
而arraylist集合没有同步锁,为线程不安全的,程序一直运行。 |
![]() 18分 |
1.应该就是5楼说的扩容了,vector成倍扩容,arraylist按50%扩容。在查询插入删除元素上,两个的复杂度是一样的。
|
![]() |
学习一下!!!!
|
![]() |
第一个不清楚;
第二个不知道; |
![]() |
过来学习一下
|
![]() |
涨知识了。。。。
|
![]() |
1、同步必然导致性能下降,但是JDK1.5之后,synchronized的效率有了很高的提升
2、mybatis sql配置化,hibernate hql |
![]() |
learning
|
![]() |
先顶再看,学学经验
|
![]() |
页游啊?
我还是以为是端游呢。 |
![]() |
我面试的游戏的公司,基本都在问并发、多线程、优化,代码基本不问。
|
![]() |
看看..学习学习
|
![]() |
进来学习一下。。。
|
![]() 2分 |
学习中~~知道了Vector扩容是成倍增长的,而ArrayList是50%增长。同步的就不用说了~~
|
![]() |
学习来了
|
![]() |
路过,学习了
|
![]() |
过了N年以后再回来看,哇,这么简单!但现在是真不会啊..学习学习…
|
![]() |
学习了
|
![]() |
第一题让我想起了当初去阿里面试的时候。那个面试官让我写arraylist的源码~结果我不知道是多少扩容的~so~
|
![]() |
一个是线程安全的,一个是不安全的 !
|
![]() |
你面试的”复读机”职位吗? |
![]() |
这面试时候不是很常见么?能扯到复读机上去? |
![]() |
我是来看评论的
|
![]() |
想学习一下,结果也没看大神级的回答,期待…
|
![]() |
游戏 从来不用这2个。
|
![]() |
服务端要用数据库啊。。 |
![]() |
直接插入写SQL语句就好,hi什么bernate呢 |
![]() |
不明觉历啊a
|
![]() |
学习了
|
![]() |
新年大吉啊啊啊啊
|
![]() |
mybatis sql全在配置文件便于管理,弊端在于不利于跟踪代码定位。 hb的hql都是写在代码里面的 后期要是改下条件什么的找起来麻烦 但是便于跟踪,纠错。
|
![]() |
学习了
|
![]() |
且学且珍惜,得认学习真正消化
|
![]() |
感觉不错,很好,学习了
|