理解EJB的参数传递

使用Eclipse+GlassFish构建简单EJB EJB,即企业级JavaBean。它是一个标准,而不是一个产品。其存在的目的是为后台开发人员提供一个标准的开发标准。它主要分成SessionBean,EntityBean和MessageDrivenBean。简而言之就是**服务器端**的一个标准。 在开发中我们需要先创建一个EJB项目,并在此EJB项目的ejbModule下创建一个带包名的SessionBean。然后在这个SessionBean... 阅读详情
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> Understanding EJB argument passing Scott Oaks Scott Oaks is a Systems Engineer for Sun Microsystems, where he focuses on practical applications of Java technology. He is the co-author, with Henry Wong, of Java Threads. TODAY'S TIP REGARDS a performance characteristic that is particularly important to certain Enterprise JavaBean (EJB) applications, although it has applicability to other types of Java applications as well. It revolves around the way in which EJBs (and, more generally, any distributed object system) pass arguments to each other; I'll discuss how this task is accomplished and when you might want to change the manner in which it is done. First, some terminology and a brief review. For the most part, arguments that are passed between two Java methods are passed by value. If you are given the code int i = 3; someMethod(i); after invoking someMethod(), we know i will have the value 3, no matter what happens inside the method invocation. i is passed by value. If you are given the code Point p = new Point(3, 3); someOtherMethod(p); after invoking someOtherMethod(), we know p will reference the same object it referenced before the method invocation—the memory location it points to is the same. But the contents of that memory may have changed. If the method calls its parameter q and executes the statement q.x = 4, then when the method returns, p will refer to the point with coordinates (4, 3). In this case, p is passed by reference. I've had semantic arguments with developers who insist that because p points to the same memory location all along, it too is passed by value. If the method executes the statement q = new Point(4, 3), then when the method returns, p will refer to the original point, which will still have the coordinates (3, 3). No matter what you choose to call it, this is the way Java works. The point is that the contents of an object can change when it is passed between methods in Java. The exception to this rule occurs with RMI and other distributed programming technology. In that case, the two methods in question are running on two different virtual machines. To get the object from one method to another, the object is serialized by the client and deserialized by the server. A side effect of this deserialization is that a copy of the object has been made, and no matter what changes are made to the contents of that object in the server, the contents of that object on the client will not change. In this case, the objects are said to be passed by value (though in those semantic wars, some prefer the term "passed by copy"). This difference in programming semantics takes a little getting used to, but it has a rationale. Clearly, a copy of the object has to be made in the server's virtual machine as it cannot share physical memory with the client's virtual machine. The standard Java object semantics could have been preserved if the copy of the object was sent back to the client and somehow overlaid in memory on top of the original object. Such a trick would have been complex and would often have had a severe impact on performance. If the object hasn't changed, it's a waste of time to copy it back. It's far better for developers to be in control of any data that needs to be sent back to the client (and to send it, for example, in the return object). This brings us to EJBs: a method invocation on an EJB is an RMI call. It is a requirement of the EJB specification that parameters passed during the method call be passed by value so that the EJB receives a copy of any object parameters (and the caller receives a copy of the return object, if applicable). Thus, your EJB client can assume that the contents of an object passed to an EJB server are not changed by the server. As it turns out, EJBs that call each other are often deployed within the same virtual machine. Think of a session bean that needs to use multiple entity beans—all of the beans are often deployed within the same virtual machine. In this case, the object serialization is not strictly necessary. The client and server both have reference to the original object. But if the server (the entity bean) changes the contents of the parameter object, the client (the session bean) will see those changes. Later, if for scaling (or other) reasons the entity beans are moved onto a different machine, the session beans will no longer see any changes to the content of the parameter object. It would be untenable to have different semantics depending on how the application is deployed; that is why all parameters between EJBs are always passed by value, even when they are within the same virtual machine. Most application servers are aware of the performance penalty paid by making an unnecessary copy of the object passed between EJBs within the same virtual machine and have an option that can be set to have these objects passed by reference (thereby avoiding the copy). If you turn on that option for an arbitrary EJB application, it is possible that the application will break. If the application is written to assume pass-by-value semantics, then the unexpected change in data contents could have a detrimental effect. On the other hand, if you write your EJBs so that they make no assumption about these semantics, then you're ahead of the game. You can gain the performance benefit from passing by reference when the EJBs are deployed within the same virtual machine, and you can still safely deploy them on multiple machines. What this means is that the EJB must never modify any object it receives as a parameter. If it returns an object, it must return a new instance of the object so that it is not inadvertently shared. The feasibility of this will depend, of course, on your application. I've seen EJB applications where enabling pass-by-reference semantics produced a 25% benefit, so if you have an application that makes a large number of EJB calls within the same virtual machine, a little forethought in application design might be to your benefit.
37、深入理解会话 EJB:从无状态到有状态的实现 本文深入解析了企业级 Java 中的会话 EJB,涵盖无状态与有状态会话 Bean 的实现、接口定义、业务逻辑处理、部署配置及客户端调用等内容。通过具体代码示例和部署描述文件,详细展示了如何在 WebLogic 环境中开发和部署 EJB 应用。同时对比了无状态与有状态 EJB 的区别,并提供了开发最佳实践和优化建议,帮助开发者全面掌握会话 EJB 技术及其应用场景。 阅读详情

相关推荐

告别拼音!用VSCode+Dosbox-X搞定汇编语言课程设计里的中文姓名显示

本文详细介绍了如何利用VSCode和Dosbox-X解决汇编语言课程设计中中文姓名显示的问题。通过配置开发环境、理解GB2312编码及正确使用汇编指令,学生可以告别拼音显示,实现中文字符的正确输出。文章还提供了完整的代码示例和常见问题排查方法,帮助读者快速掌握这一实用技能。

weixin_30872337的博客 425

解决客户端调用EJB远程接口传递基本数据类型数组失败

最近做项目中发现一个问题,调用EJB远程接口时,传递的是基本数组类型如(int[] long[]等等...),发布运行后,产生如下错误。 Specified calling class, [J could not be found for sun.misc.Launcher$AppClassLoader@1c78e57 at org.jboss.ejb3.common.lang.Seria...

华家乐博客 222

BRep实战指南:从理论到文件格式的全面解析

本文全面解析BRep(边界表示法)从基础概念到文件格式的实战应用。详细介绍了BRep的数学定义、工业应用场景,以及STEP、IGES等主流文件格式的对比与使用技巧,帮助读者掌握三维建模核心技术并优化性能。

weixin_29235923的博客 410

线程方法的解析

A synchronized Java语言的关键字,当它用来修饰一个方法或者一个代码块的时候,能够保证在同一时刻最多只有一个线程执行该段代码。 B C D 都是Object类中的方法 notify(): 是唤醒一个正在等待该对象的线程。 notifyAll(): 唤醒所有正在等待该对象的线程。 E sl...

baochiao8738的博客 207

人形机器人专题:人形机器人关节,从Optimus选型看关节的发展

今天分享的是深度研究报告:《(报告出品方:中泰页。

GPT20236688的博客 3226

7-1 链式基数排序 (20 分)

7-1 链式基数排序 (20 分) 实现链式基数排序,待排序关键字n满足1≤n≤1000,最大关键字数位≤5。 输入样例: 第一行输入待排序个数n(1≤n≤1000),再输入n个数(n的数位≤5)。 10 278 109 63 930 589 184 505 269 8 83 输出样例: 输出每趟分配-收集后链表中的关键字,趟数为序列中最大值的数位(如样例中930的数位为3),每行结尾有空格。 930 63 83 184 505 278 8 109 589 269 505 8 109 930 63 26

OwemShu的博客 4240

EJB学习笔记-6-传值和传址

传值就是remote方式,参数必须实现序列化 传址就是local方式。 entitybean: package com.manfred.entity; import java.io.Serializable; public class User implements Serializable { private String username; private int id;

ManfredShuai的博客 503

不会ps,你也可以成为ps高手,最强傻瓜式人像一键磨皮美白瘦脸美妆PS插件

比如:美肤是用来去斑点的,如果效果不太理想,就加大百分比,反之就减小。瘦脸如果脸胖的就打开,正常的就关闭。所谓的一键调节,要不只能调节一种效果,要不就是个预设,然后让你自己再调。同时,该软件还加入了贴心的批量处理功能,能同时处理上千张照片,让您喝着茶也能将工作做完。、自动检测照片中的人脸,包括鼻子,嘴巴,耳朵,眼睛和眉毛。、依托强大的脸部识别功能,可以高效的对人物全身皮肤进行智能识别,处理,使肤质平滑、过渡均匀。,这是网上下载的模糊照片,经过简单处理,你可以发现,眼睛变的更亮,皮肤更白,眼袋消失。

心语家园 - www.xinyucn.cc 2903

EJB

精通EJB第二版 笔记 第一章: 构建一个大型的商务系统时需要考虑的因素 远程方法调用 平衡负载 透明故障恢复 后台集成 事务 群集 动态重部署 无损关机 登录和检查 系统管理 线程化 面向消息的中间件 对象生命周期 资源共享 安全 高速缓(冲)存 可重用中间件 EJB简介 是一个关于用JAVA语言开发的可部署的服务器端组件的组件体系结构。 ...

我的世界里头,谁懂我! 309

8.Python基础语法(五)续【光说不练假把式,上题】

Python基础语法(二) 有关于Python循环语句的几道实操,让大家理解知识点更深更透彻~

孤寒者的博客 2万+

Vue - ElementUI el-date-picker 周日期选择器(type=week),获取开始和结束的年月日、当前选择日期的周数等,支持将选择范围修改为 “礼拜一到礼拜日“(提供示例源码)

vue,element-ui,DatePicker日期选择器,vue2elementUI日期选择器选择一周7天的数据格式怎么拿到,el-date-picker设置type等于week后怎么设置format属性,format和value-format怎么设置,范围选择器周,一周,选择一周7天时间,el-date-picker,周,type=week,周选择器,面板显示周数,显示第n年第n周数据,详细示例代码教程,elementui官方文档,vue2element-UI日期时间选择器怎么设置week周选

🏆 前端领域优质创作者 6439

如何理解JAVA 参数传递总是值传递(pass-by-value )

有人说java 参数传递在对primitive类型的参数传递时候是值传递,对对象参数的传递是引用传递。 可是JAVA规范里面却说的是总是值传递。 看看这个图就理解了。  对传入的参数总是有个copy的过程。因为primitive类型的参数在JVM中,参数中存储的就是本身的值,copy后的参数和原来的参数就完全独立了。对于对象类型的参数,参数中存储的是对象在h

交换一个思想,能得到俩思想 3880

vs2017配置liblas库+测试代码

之前已经配置好pcl(vs2017配置pcl),可以单独配置liblas,也可以在原有pcl属性表的基础上继续配置

孙悟空 4023

【EJB学习笔记】——远程调用和本地调用

EJB应用可以发布为远程调用和本地调用。 从字面意思来理解,远程调用就是客户端(调用的模块)和服务端(被调用的模块)“不在一起”,“相隔很远”;本地调用就是客户端(调用的模块)和服务端(被调用的模块)“在一起”,“相隔很近”。 实质就是,客户端与服务端的EJB对象不在同一个JVM进程中,就是远程调用;客户端与服务端的EJB对象在同一个JVM进程中,就是本地调用。 @Remote注解用来定义用

点滴汇聚,智在积累。——Danny 5299

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

ADF 入门帮助

ADF 入门帮助 本文是由英文帮助翻译所得: “任务流 task flows”可以包括非可视化的组件,比如方法调用。 “页片段 page fragment”可以运行在一个页面的某个局部区域,最大限度地提高复用性。 ADF Task Flow是在JSF Controller的基础上扩展而来的,它除了包括View Activities和导航规则之外,还可以包括method calls等

qq136722979的专栏 2508

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

EJB3.0 有状态会话bean无状态会话bean详解

EJB3.0 有状态会话bean无状态会话bean详解 (2010-11-09 16:16:42) from http://blog.sina.com.cn/s/blog_59d6717c0100mbn1.html 标签:  ejb   ejb入门   java   分布式   架构   有状态   无状态

阿义的专栏 607

资产系统分布式理解

首先,说一下ejb的调用原理:这里使用EJB相当于建立了两个项目,一个为EJB端项目,保存的是你的sessionBean和entityBean,纯后台代码,一个为Web端项目,保存的是jsp/Servlet部分的代码,可以通过jndi调用后台的sessionBean,两个项目可以分别部署到两台服务器上,这样就实现了分布式,开发ejb端的开发人员不需要知道具体业务逻辑是什么,只需要根据需要编写操作数

JLegend的专栏 825

EJB中有状态会话Bean 和 无状态会话Bean 的区别

session  Bean:分有状态会话Bean和无状态会话Bean两种,主要目的是提供程序逻辑层;Entity  Bean:资料组件,主要目的是提供程序资料;下面主要对Session  Bean讨论 现实中,很多朋友对两种session bean存在误解,认为有状态是实例一直存

traceofsun的专栏 541

EJB3.0查询语句JPQL用法

自己的理解:本身J2EE中JPA就是对OR框架的映射,所以在查询的时候也应该是查询对象而不是想SQL那样查询表来获取所需要的字段或者是名称,类似与HQL中如果你想查询几个字段的Object的话 就要实现很多的构造函数,或者是利用map来接受返会的非所有字段的实体,例如: Query query=manager.createQuery("select user from Users user wh...

liruichuan的专栏 1547

如何理解SpringIOC

SpringIOC是Spring Core最核心的部分,要了解控制反转(Inversion of Control),我觉得有必要先了解软件设计的一个重要思想:依赖倒置原则。 1、高层模块不应该依赖底层模块,二者都应该依赖抽象2、抽象不应该依赖细节,细节应该依赖抽象。3、依赖倒置的中心思想是面向接口编程。4、依赖倒置原则是基于这样的设计理念:相对于细节的多变性,抽象的东西要...

一枚野生程序员 —— Tim 710

阿里Java二面:面试官问我如何理解SpringIOC,这不有嘴就行?

SpringIOC 是 Spring Core 最核心的部分,要了解控制反转 (Inversion of Control),我觉得有必要先了解软件设计的一个重要思想:依赖倒置原则。SpringIOC 是 Spring Core 最核心的部分,要了解控制反转 (Inversion of Control),我觉得有必要先了解软件设计的一个重要思想:依赖倒置原则。1、高层模块不应该依赖底层模块,二者都应该依赖抽象2、抽象不应该依赖细节,细节应该依赖抽象。3、依赖倒置的中心思想是面向接口编程。4、依赖倒置原则是基于

m0_62051288的博客 119

IBM的JAVA笔试题

转载地址:http://tag.youkuaiyun.com/Article/a335d168-3e0d-4a16-8af6-cac76af0471c.html1.    简答题:   a)  在你心中,J2EE是什么样的?请用三句话描述清楚。 b)  会话EJB主要分为哪两种类型?它们的主要区别是什么?谁的性能更好,为什么?   c)  EJB的开发人员必须为每个EJB提供哪三个类型的Java对象?这些Ja

shuangr的专栏 1313

视频教程-Spring MVC 入门学习视频-Java

Spring MVC 入门学习视频 Java讲师,多年培训经验,曾参与开发过...

weixin_28920493的博客 200
上一篇: Java网络加载协议(JNLP)及Java Web Start
下一篇: Java's top guns -- 2002 Editors' Choice Awards
java169
博客等级 码龄19年 27粉丝 2568原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值