订阅所有JSP/Servlet的日志 订阅 | 这是最新一篇日志 上一篇 | 下一篇日志 下一篇 ]
EJB

提高EJB性能的十大技巧

EJB调用是耗时、费力的。怎么提高EJB的性能?我们为解决这一问题,开始边写边讨论。等到完成了,我才发现,我们所应用的技巧总结一下,竟有十条。把提高EJB性能的这些技巧总结一下,为以后的项目做参考。

1.用一个Session Bean封装多个Entity Bean,将原来的多个Entity Bean的Remote调用和Local调用封装在一个Session Bean中。所以建立一个ServerFacade,它为多个对象提供统一获取EJB Home和获取对象的接口。ServerFacade为程序要用到的所有EJB的home handle提供缓存,提高访问JNDI Name的时间,达到提高访问效率的目的。以后查找JNDI Name的方法都应写在接口里,调用时直接从接口调用。

2.在EJB的Remote接口中使用粗粒度的方法,不推荐使用细粒度方法。

3.如果EJB的Remote接口获取成功,应不再使用Remote接口,而是将Remote接口构造成一个一般的Java对象,通过调用一般的JAVA对象的方法来达到减少对网络的访问。

4.如果你部署EJB客户端和EJB在相同的JVM上,建设使用EJB2.0规范的Local接口代替Remote接口。

5.用"transient"关键字声明不必要的数据变量,替代以前的"public"、"private"等,避免不必要的数据变量占用网络资源。示例:
1
2
3
4
5
6
7
public class DemoCMP implements EntityBean { 
transient EntityContext entCtx; 
transient InitialContext initCtx; 
public String id; 
public String description; 
… 
} 

6.在ejb-jar.XML部署文件中,对Session Bean中非事务的方法,将trans-attribute属性赋为"NotSupported"或"Never"
1
2
3
4
5
6
7
8
9
10
11
12
<ejb-jar> 
… 
<assembly-descriptor> 
<container-transaction> 
<method> 
<ejb-name>abookesessionBean</ejb-name> 
<method-name>*</method-name> 
</method> 
<trans-attribute>NotSupported</trans-attribute> 
</container-transaction> 
</assembly-descriptor> 
</ejb-jar> 

7. 设置事务的超时时间,在JBoss中,要修改${jboss.home}/server/${jboss.configuration}/conf/jboss-service.xml ,如下所示:

1
2
3
4
5
6
7
8
<server> 
… 
<mbean code="org.jboss.tm.TransactionManagerService" 
name="jboss:service=TransactionManager"> 
<attribute name="TransactionTimeout">300</attribute> 
</mbean> 
… 
</server> 

8.当事务锁定数据库的行记录时,事务应跨越可能的最小的时间。

9.调整EJB 服务器的各种参数,如线程数、EJB池大小、连接池参数等。以在JBoss修改连接池参数为示例,进行说明。如果JBoss和MySQL相连,配置${jboss.home}/server/${jboss.configuration}/deploy/mysql-service.xml,来修改连接池参数,包括MinSize、MaxSize、BlockingTimeoutMillis、IdleTimeoutMinutes、Criteria等,各参数的含义如下所示:

i.MinSize :连接池保持的最小连接数。

ii. MaxSize :连接池保持的最大连接数。

iii. BlockingTimeoutMillis :抛出异常前最大的等待连接时间。

iv. IdleTimeoutMinutes :关闭连接前连接空闲的最大时间。

v. Criteria :有ByContainerAndApplication、ByContainer、ByApplication和ByNothing等值。

下面是一个例子:

1
2
3
4
5
6
7
8
9
10
11
<depends optional-attribute-name="ManagedConnectionPool"> 
<!--embedded mbean--> 
<mbean code="org.jboss.resource.connectionmanager.JBossManagedConnectionPool" 
name="jboss.jca:service=LocalTxPool,name=MySqlDS"> 
<attribute name="MinSize">0</attribute> 
<attribute name="MaxSize">50</attribute> 
<attribute name="BlockingTimeoutMillis">5000</attribute> 
<attribute name="IdleTimeoutMinutes">15</attribute> 
<attribute name="Criteria">ByContainer</attribute> 
</mbean> 
</depends> 

10.对于数据库事务,应选择较低成本的事务等级,避免造成坏数据。递增成本的事务等级包括:

TRANSACTION_READ_UNCOMMITED,
TRANSACTION_READ_COMMITED,
TRANSACTION_REPEATABLE_READ,
TRANSACTION_SERIALIZABLE

平均得分
(0 次评分)





文章来自: 360doc
标签:
评论: 21 | 查看次数: 1556
  • 共有 21 条评论
  • 1
  • 2
  • |
  • >>
游客 [2008-08-25 23:01:22]
游客 [2008-08-22 21:43:48]
游客 [2008-08-22 15:25:32]
游客 [2008-08-18 14:14:04]
游客 [2008-08-07 13:33:42]
For those who are inexperienced with purchasing the lotro gold,lotro accountsand lotro powerleveling from lotro goldsellers,there are many lotro gold sellers that are frauds and scams that can not be removed from the internet.Firstly.reviewsof the lord of the rings online gold sellers and hearing out what other customers have to see can be very helpful.
wow gold
buy wow gold
lotro gold
aoc gold
lineage 2 adena
wow gold
buy wow gold
lotro gold
aoc gold
lineage 2 adena

lotro gold
lotro gold for sale
lord of the rings online gold
游客 [2008-08-07 13:33:22]
游客 [2008-08-06 14:19:37]
游客 [2008-07-24 05:57:08]
游客 [2008-07-18 15:46:35]
Best place to start is in Bloodhoof Village in Mulgore.wow geld Go speak to Harn Longcast and buy Brilliant Smallfish him.mp3 players Now start fishing in Stonebull Lake.mp3 player Equip your rod and then apply the shiny bauble lure to it.wow level service as this will make catching fish easier.You'll want to catch about 60 Brilliant minutes.mp3 players You'll find that by the time you have Smallfish.mp3 player you'll also have about 30 Longjaw Mud Snappers.wow Once you have 60.mp3 players cook them.mp3 player You can own fire or jog back.wow gold to Harn Longcast and use the fire in front of him.wow schnell gold Cook the Brilliant Smallfish.gold für wow then at level 50 start cooking Longja.wow gold paypal Mud Snappers (after learning the recipe you bought earlier).You'll need to go and catch Longjaw.gold in wow Mud Snappers now and the place for these is.wow gold 1000 the pond in Orgrimmar by Lumark the Fishing trainer.wow power leveling (I know you've been catching quite a few where you are.wowgold but the "drop rate" is a lot better in Orgrimmar).Between levels 50 and 75 go and cooking.wowgold You'll now need to catch about 30 Longjaw 100.world of warcraft power leveling Now go to Mill in Hillsbrad and buy Bristle Whisker.wow golds Catfish recipe off of Derak Nightfall.cheapest wow gold Go to Mill and fish for Bristle Whisker Catfish.wow lvl Depending on your cooking level.world of warcraft power leveling Between levels 125 expert cooking from trainer.buy mp3 players You'll need and buy a book for your Fishing level.
Speak tobuy the book Expert Fishing: The Bass and You.Once your up to 175 cooking, go to Shadowprey Village in Desolace.
游客 [2008-07-18 15:46:04]
Hey whats up guys New to the board.wow gold I'm in a bit of a dilema.wow gold welcome to my blog. mining and skinning as professions.world of warcraft gold I've made tons of with this guy.wow geld Enough money that I was able to buy.wow powerlevel my mount at level 40 with no problem at all.buy wow gold So now Im about to create an ALT toon and was wondering.wow which professions would compliment my.wow gold level 44 warrior and make me money at the same time.cheap wow gold One of my friends sayd I should go with disenchanting.serveur wow and blacksmithing but I don't know if there.wow europe is any money to be made in those.cheapest wow gold What do you guys think.wow power leveling Blacksmithing doesn't really pay off that well.wow powerleveling And I think that your warrior is geared quite well.gold wow so that the blacksmithing skill would have.mp3 players to be levelled quitea lot before you.mp3 player can make some nice and useful things.One crafting skill that compliments a warrior is alchemy.wow gold You can brew potions that he can consume.mp3 player and which are quite helpful in battle.zubehoer mp3 player There are potions to replenish lost health or rage.wow gold kaufen and there are battle and guardian elixirs to give you a boost.mp3 You could try enchanting to boost your warrior's gear.mp4 but then your other skill would have to be. mp4one where you can create green items (such as tailoring or leatherworking) to be disenchanted.
You can also send any useless greens you find with your warriorwow gold to your alt.but it's easier if you can also make your own.
游客 [2008-07-18 15:40:39]
游客 [2008-06-05 09:59:57]
某美独资(500强)招聘java/j2ee/QA,月薪5-15k
chloe_hb159@hotmail.com
chloe@21cnmanager.com
游客 [2008-06-02 14:33:22]
游客 [2008-05-23 15:57:34]
游客 [2008-05-23 15:57:00]
  • 共有 21 条评论
  • 1
  • 2
  • |
  • >>
发表评论
昵 称:  登录
内 容:
选 项:
字数限制 1000 字 | UBB代码 开启 | [img]标签 开启