- 浏览: 213066 次
- 性别:
- 来自: 南京
文章分类
- 全部博客 (344)
- Spring (38)
- Spring-mvc (9)
- hibernate (21)
- mvn (5)
- shiro (2)
- java script (14)
- jquery (9)
- ext (6)
- asm (1)
- 大数据 (2)
- 分布式 (14)
- node.js (1)
- webservice (4)
- java (47)
- oracle (36)
- mysql (11)
- sql (33)
- 工具 (13)
- github (3)
- tomcat (4)
- jetty (1)
- struts2 (1)
- android (13)
- xml (1)
- primefaces (1)
- secure (2)
- 编码 (3)
- EL (3)
- jsp (2)
- css (7)
- java 算法 (3)
- 移动端 (2)
- other (3)
- mybatis (1)
- 缓存 (1)
- 乱 (1)
- apache commons (2)
- ehcache (1)
- 方法论 (1)
- activiti (1)
- sqlserver (5)
- 业务 (4)
- 数据结构 (5)
- liux (1)
- commons (4)
- jvm (2)
最新评论
-
张yyyyyy:
不明觉厉
一次sql 调优心得 -
masuweng:
某一类日期范围内每7天一组的销量之和,以及行转列 -
faradayroger:
[color=green][color=red][/color ...
定时JOB,去请求数据,并找出最新数据持久化 -
cainiao1923:
java-lxm 写道 写文章贴个图也不好好贴....难道是网 ...
spring 注入static属性 -
java-lxm:
写文章贴个图也不好好贴
spring 注入static属性
原文:https://forum.hibernate.org/viewtopic.php?p=2386803
Hi, I've written a small test to measure the memory consumption of my Hibernate code. It seem that getting a List of objects with the list() method of a Query uses much more memory than creating the List manually by using a ScrollableResult.
The ScrollableResult memory consumption is almost identical to the consumption of a pure JDBC implementation. The list() memory consumption needs much more MB. In my case with my Database 50.000 Object need approximately 13 MB with ScrollableResult and 23 MB with list()!!
Can anybody explain this behaviour? Is my code wrong?
Hibernate Version: 3.2.2ga
Windows XP SP2
Database: Oracel 10g
Testcode:
Note: You have to replace the HQL Query with your Hibernate Objects!
Code:
public class HibernateMemoryConsumptionTest extends TestCase {
private int size = 50000;
private int repeats = 2;
private boolean trackMemoryConsumption = true;
private Runtime runtime;
protected void setUp() throws Exception {
super.setUp();
runtime = Runtime.getRuntime();
}
protected void tearDown() throws Exception {
super.tearDown();
runtime = null;
}
public void testHibernateWithOneSession() {
// init
HibernateUtil.getSessionFactory();
long heap1 = 0;
long heap2 = 0;
long start = System.currentTimeMillis();
StatelessSession session = null;
Transaction tx = null;
List results = null;
try {
session = HibernateUtil.getSessionFactory().openStatelessSession();
for (int i = 0; i < repeats; i++) {
if (trackMemoryConsumption) {
System.err
.println("Note: Memory measurement can influence time measurement!");
runGC();
heap1 = usedMemory(); // Take a before heap snapshot
}
tx = session.beginTransaction();
Query query = session
.createQuery("FROM Cashflow ");
query.setFirstResult(1);
query.setMaxResults(size);
results = query.list();
tx.commit();
assertEquals(size, results.size());
if (trackMemoryConsumption) {
heap2 = usedMemory(); // Take an after heap snapshot:
final long heapsizeDiff = heap2 - heap1;
System.out.println("'before' heap: " + heap1
+ ", 'after' heap: " + heap2);
System.out.println("heap delta: " + heapsizeDiff / 1024d
/ 1024d + " MB");
}
results = null;
runGC();// aufräumen für nächste schleife
}
} catch (Throwable t) {
t.printStackTrace();
if (tx != null) {
tx.rollback();
}
throw new PersistenceException(t);
}
long end = System.currentTimeMillis();
System.out.println("runtime with list() "
+ repeats + " repeats with " + size + " Cashflows = "
+ ((end - start) / (double) repeats));
}
public void testHibernateWithScrollableResult() {
// init wird nicht mitgezählt!
HibernateUtil.getSessionFactory();
long heap1 = 0;
long heap2 = 0;
long start = System.currentTimeMillis();
StatelessSession session = null;
Transaction tx = null;
ScrollableResults results = null;
List cashFlows = null;
try {
session = HibernateUtil.getSessionFactory().openStatelessSession();
for (int i = 0; i < repeats; i++) {
cashFlows = new ArrayList();
if (trackMemoryConsumption) {
System.err.println("Note: Memory measurement can influence time measurement!");
runGC();
heap1 = usedMemory(); // Take a before heap snapshot
}
tx = session.beginTransaction();
Query query = session
.createQuery("FROM Cashflow ");
query.setFirstResult(1);
query.setMaxResults(size);
results = query.scroll(ScrollMode.FORWARD_ONLY);
while (results.next()) {
cashFlows.add(results.get(0));
}
tx.commit();
assertEquals(size, cashFlows.size());
if (trackMemoryConsumption) {
heap2 = usedMemory(); // Take an after heap snapshot:
final long heapsizeDiff = heap2 - heap1;
System.out.println("'before' heap: " + heap1
+ ", 'after' heap: " + heap2);
System.out.println("heap delta: " + heapsizeDiff / 1024d
/ 1024d + " MB");
}
results = null;
cashFlows = null;
runGC();// aufräumen für nächste schleife
}
} catch (Throwable t) {
t.printStackTrace();
if (tx != null) {
tx.rollback();
}
throw new PersistenceException(t);
}
long end = System.currentTimeMillis();
System.out.println("runtime with ScrollableResults "
+ repeats + " repeats with " + size + " Cashflows = "
+ ((end - start) / (double) repeats));
}
private void runGC() throws Exception {
// It helps to call Runtime.gc()
// using several method calls:
for (int r = 0; r < 4; ++r)
_runGC();
}
private void _runGC() throws Exception {
long usedMem1 = usedMemory(), usedMem2 = Long.MAX_VALUE;
for (int i = 0; (usedMem1 < usedMem2) && (i < 500); ++i) {
runtime.runFinalization();
runtime.gc();
Thread.currentThread().yield();
usedMem2 = usedMem1;
usedMem1 = usedMemory();
}
}
private long usedMemory() {
return runtime.totalMemory() - runtime.freeMemory();
}
}
Hi, I've written a small test to measure the memory consumption of my Hibernate code. It seem that getting a List of objects with the list() method of a Query uses much more memory than creating the List manually by using a ScrollableResult.
The ScrollableResult memory consumption is almost identical to the consumption of a pure JDBC implementation. The list() memory consumption needs much more MB. In my case with my Database 50.000 Object need approximately 13 MB with ScrollableResult and 23 MB with list()!!
Can anybody explain this behaviour? Is my code wrong?
Hibernate Version: 3.2.2ga
Windows XP SP2
Database: Oracel 10g
Testcode:
Note: You have to replace the HQL Query with your Hibernate Objects!
Code:
public class HibernateMemoryConsumptionTest extends TestCase {
private int size = 50000;
private int repeats = 2;
private boolean trackMemoryConsumption = true;
private Runtime runtime;
protected void setUp() throws Exception {
super.setUp();
runtime = Runtime.getRuntime();
}
protected void tearDown() throws Exception {
super.tearDown();
runtime = null;
}
public void testHibernateWithOneSession() {
// init
HibernateUtil.getSessionFactory();
long heap1 = 0;
long heap2 = 0;
long start = System.currentTimeMillis();
StatelessSession session = null;
Transaction tx = null;
List results = null;
try {
session = HibernateUtil.getSessionFactory().openStatelessSession();
for (int i = 0; i < repeats; i++) {
if (trackMemoryConsumption) {
System.err
.println("Note: Memory measurement can influence time measurement!");
runGC();
heap1 = usedMemory(); // Take a before heap snapshot
}
tx = session.beginTransaction();
Query query = session
.createQuery("FROM Cashflow ");
query.setFirstResult(1);
query.setMaxResults(size);
results = query.list();
tx.commit();
assertEquals(size, results.size());
if (trackMemoryConsumption) {
heap2 = usedMemory(); // Take an after heap snapshot:
final long heapsizeDiff = heap2 - heap1;
System.out.println("'before' heap: " + heap1
+ ", 'after' heap: " + heap2);
System.out.println("heap delta: " + heapsizeDiff / 1024d
/ 1024d + " MB");
}
results = null;
runGC();// aufräumen für nächste schleife
}
} catch (Throwable t) {
t.printStackTrace();
if (tx != null) {
tx.rollback();
}
throw new PersistenceException(t);
}
long end = System.currentTimeMillis();
System.out.println("runtime with list() "
+ repeats + " repeats with " + size + " Cashflows = "
+ ((end - start) / (double) repeats));
}
public void testHibernateWithScrollableResult() {
// init wird nicht mitgezählt!
HibernateUtil.getSessionFactory();
long heap1 = 0;
long heap2 = 0;
long start = System.currentTimeMillis();
StatelessSession session = null;
Transaction tx = null;
ScrollableResults results = null;
List cashFlows = null;
try {
session = HibernateUtil.getSessionFactory().openStatelessSession();
for (int i = 0; i < repeats; i++) {
cashFlows = new ArrayList();
if (trackMemoryConsumption) {
System.err.println("Note: Memory measurement can influence time measurement!");
runGC();
heap1 = usedMemory(); // Take a before heap snapshot
}
tx = session.beginTransaction();
Query query = session
.createQuery("FROM Cashflow ");
query.setFirstResult(1);
query.setMaxResults(size);
results = query.scroll(ScrollMode.FORWARD_ONLY);
while (results.next()) {
cashFlows.add(results.get(0));
}
tx.commit();
assertEquals(size, cashFlows.size());
if (trackMemoryConsumption) {
heap2 = usedMemory(); // Take an after heap snapshot:
final long heapsizeDiff = heap2 - heap1;
System.out.println("'before' heap: " + heap1
+ ", 'after' heap: " + heap2);
System.out.println("heap delta: " + heapsizeDiff / 1024d
/ 1024d + " MB");
}
results = null;
cashFlows = null;
runGC();// aufräumen für nächste schleife
}
} catch (Throwable t) {
t.printStackTrace();
if (tx != null) {
tx.rollback();
}
throw new PersistenceException(t);
}
long end = System.currentTimeMillis();
System.out.println("runtime with ScrollableResults "
+ repeats + " repeats with " + size + " Cashflows = "
+ ((end - start) / (double) repeats));
}
private void runGC() throws Exception {
// It helps to call Runtime.gc()
// using several method calls:
for (int r = 0; r < 4; ++r)
_runGC();
}
private void _runGC() throws Exception {
long usedMem1 = usedMemory(), usedMem2 = Long.MAX_VALUE;
for (int i = 0; (usedMem1 < usedMem2) && (i < 500); ++i) {
runtime.runFinalization();
runtime.gc();
Thread.currentThread().yield();
usedMem2 = usedMem1;
usedMem1 = usedMemory();
}
}
private long usedMemory() {
return runtime.totalMemory() - runtime.freeMemory();
}
}
发表评论
-
更新的想法
2017-04-25 17:58 472全部更新的话,可以query-copy-delete-in ... -
hibernate 查询VO
2017-03-02 15:03 708需求很简单,就是关联两个实体,多查询一个name出来。这样就 ... -
(转)对The method createBlob() is undefined for the type Hibernate异常的解决办法
2017-02-11 08:44 1135REFS:http://blog.csdn.net/zjw ... -
(转)Hibernate 3保存BOLB的方法,mysql(Hibernate4不适合此法)
2017-02-11 08:40 411Tutorial:Saving/Retreving BLO ... -
(转)Java数据类型和MySql数据类型对应表
2017-02-10 14:13 818java mysql 数据类型对照 类型名称 ... -
(转)hibernate sqlQuery mysql别名问题
2017-02-10 14:11 578项目环境:hibernate3.6.1 mysql5.7 ... -
AliasToBeanResultTransformer 。问题:Could not find setter for 0 on class MyClass
2017-02-10 14:05 1065As you are using AliasToBeanR ... -
mysq 的decimal类型与hibernate 的 setResultTransformer
2017-02-10 12:06 761mysql数据库里是decimal类型的话(powerd ... -
同名方法参数存在继承关系时候,调用哪个的疑问。{系列基础不确定问题}
2017-02-07 11:51 267private void setResultTransfo ... -
(转)Path expected for join!错误处理
2017-02-07 11:43 1031在hibernate中,进行连接查询时,如果使用join语句 ... -
(转)hibernate中的addEntity setResultTransformer的比较
2017-02-07 11:38 660如果使用原生sql语句进行query查询时,hibe ... -
(转) hibernate中使用数据库关键字(保留字)
2016-12-20 11:12 1196在hibernate中,当一个实体对象使用了数据库保留 ... -
(转)hibernate 二级缓存配置
2016-12-14 11:58 359在applicationContext.xml文件中添 ... -
hql语句的from不支持子查询
2016-11-10 15:26 1046上午,跨表查询,写了很长的hql语句,就是出错!后来上网查查, ... -
hibernate PK生成策略总结
2016-11-09 10:12 611hibernate提供的主键生成策略,使我 ... -
表的同步、hibernate随想
2016-10-12 15:11 380两个相同表(A-》B)之间数据同步方案-- 1.直接删除B表 ... -
主键问题
2016-03-30 17:30 384问题: 附表用到主表的主键ID,在先persist主表之后, ... -
上传文件到数据库
2016-03-26 16:29 591在hibernate Annotation中,实体BLOB ... -
hibernate异常坑人
2015-06-23 14:36 761org.hibernate.QueryParameterEx ... -
Note that HQL subqueries can occur only in the select or where clauses.
2014-10-10 16:19 592Note that HQL subqueries can oc ...
相关推荐
循环滚动列表,做个记录。以后再继续改进。...............000000000000000000000
Hacer Scroll en Contenedor
yarn add react-infinite-scroll-list 注意:该库基于 API,尚未得到广泛支持。 检查并根据需要添加 ! 在上查看示例 用法 将模块导入您的应用程序: // From ES6 import InfiniteList from 'react-infinite-...
UGUI Super ScrollView动态无限滑动列表,功能很多,Demo场景均有。
现场演示 https://codesandbox.io/s/live-demo-virtual-list-e1ww1 使用简单npm install vue-virtual-scroll-list --save 根成分: < template> < div> < virtual xss=removed xss=removed xss=removed xss=removed>...
用法 var list = new ScrollList ( {// use `transform:translateY()` instead of `top` to offset contents?useTransforms : false ,// debounce scroll events using requestAnimationFrame()?bufferedScrolling :...
一、query.scroll()和query.setFirstResult(),query.setMaxResults();这两种方法都可以取到一定范围内的数据,用来数据分页显示。那么两者区别,以及两者的效率如何? 答:1.scroll是用JDBC2.0的可滚动结果集实现;...
smoothScroll.js 是极小的,符合标准的平滑滚动脚本,无依赖,支持 Firefox, Chrome, IE10, Opera 和 Safari。使用:[removed][removed]示例:var smoothScroll = require('smoothscroll'); var exampleBtn = ...
Vuescroll 是一个基于 vue.js 2.X的虚拟滚动条,它拥有多个模式可供你选择: slide 模式、native 模式和pure-native模式, 并且它还支持定制滚动条的样式,检测内容尺寸变化、能够使内容分页、支持上拉-刷新,下推...
scroll事件 addeventlistener(name,callback,optional,useCapture) useCapture:事件是否用捕获事件,从外到里,true 默认为false:使用冒泡事件,从里到外 optional:{ passive:false时,阻止默认事件,ture时...
jquery endlessEndless Scroll.rar jquery endlessEndless Scroll.rar
better-scroll.js
scroll 最基本例子 没有其他的杂质
unity自制scroll view面板,scroll bar 可一拖动drag 拖动图标进入指定位置,drop即可更改grid内容 可以修改成选择制定内容
用于解决一个界面内同时存在多个不同类型监听冲突的方法,实现类似QQHD版窗口拖动滚动点击效果
失效的scroll-x 在微信小程序的文档中,使用...贴上部分wxml和wxss代码… <!-- 横向滚动商品 --> <scroll class='scroll-box'> <image src='https://ss2.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/i
最后经过不懈的努力,找了很多资料,才发现,居然要设置scroll-view高度,于是我在.wxss里设置了高度为100%: .scrollStyle{ width: 100%; height: 100%; display: flex; flex-direction: column; } 居然无效,...
懂的人都知道, MAC必装, 让鼠标像触摸板一样的平滑滚动
1.下载Smooth Scroll Links插件,将压缩包解压后,把文件夹上传到wp-content/plugins/目录下,登录WordPress管理后台,点击“Plugins”找到上传的插件,激活该插件。 2.插件激活后,在后台的左侧栏中“Settings”---...
UGUI 之ScrollView剖析,及自定义设计,游戏等级的UI设计,可滑动切换;