`

Java笔试面试

阅读更多

1、栈与堆都是Java用来在Ram中存放数据的地方。与C++不同,Java自动管理栈和堆,程序员不能直接地设置栈或堆。

Java的堆是一个运行时数据区,类的对象从中分配空间。这些对象通过new、newarray、anewarray和multianewarray等指令建立,它们不需要程序代码来显式的释放。堆是由垃圾回收来负责的,堆的优势是可以动态地分配内存大小,生存期也不必事先告诉编译器,因为它是在运行时动态分配内存的,Java的垃圾收集器会自动收走这些不再使用的数据。但缺点是,由于要在运行时动态分配内存,存取速度较慢。

栈的优势是,存取速度比堆要快,仅次于寄存器,栈数据可以共享。但缺点是,存在栈中的数据大小与生存期必须是确定的,缺乏灵活性。栈中主要存放一些基本类型的变量(,int, short, long, byte, float, double, boolean, char)和对象句柄。

栈有一个很重要的特殊性,就是存在栈中的数据可以共享。假设我们同时定义:

int a = 3;
int b = 3; 

编译器先处理int a = 3;首先它会在栈中创建一个变量为a的引用,然后查找栈中是否有3这个值,如果没找到,就将3存放进来,然后将a指向3。接着处理int b = 3;在创建完b的引用变量后,因为在栈中已经有3这个值,便将b直接指向3。这样,就出现了a与b同时均指向3的情况。

这时,如果再令a=4;那么编译器会重新搜索栈中是否有4值,如果没有,则将4存放进来,并令a指向4;如果已经有了,则直接将a指向这个地址。因此a值的改变不会影响到b的值。

要注意这种数据的共享与两个对象的引用同时指向一个对象的这种共享是不同的,因为这种情况a的修改并不会影响到b, 它是由编译器完成的,它有利于节省空间。而一个对象引用变量修改了这个对象的内部状态,会影响到另一个对象引用变量。

String是一个特殊的包装类数据。可以用:

String str = new String("abc");
String str = "abc"; 

两种的形式来创建,第一种是用new()来新建对象的,它会在存放于堆中。每调用一次就会创建一个新的对象。而第二种是先在栈中创建一个对String类的对象引用变量str,然后查找栈中有没有存放"abc",如果没有,则将"abc"存放进栈,并令str指向”abc”,如果已经有”abc” 则直接令str指向“abc”。
比较类里面的数值是否相等时,用equals()方法;当测试两个包装类的引用是否指向同一个对象时,用==,下面用例子说明上面的理论。

String str1 = "abc";
String str2 = "abc";
System.out.println(str1==str2); //true 

可以看出str1和str2是指向同一个对象的。

String str1 =new String ("abc");
String str2 =new String ("abc");
System.out.println(str1==str2); // false 

用new的方式是生成不同的对象。每一次生成一个。

因此用第二种方式创建多个”abc”字符串,在内存中其实只存在一个对象而已. 这种写法有利与节省内存空间. 同时它可以在一定程度上提高程序的运行速度,因为JVM会自动根据栈中数据的实际情况来决定是否有必要创建新对象。而对于String str = new String("abc");的代码,则一概在堆中创建新对象,而不管其字符串值是否相等,是否有必要创建新对象,从而加重了程序的负担。

另一方面, 要注意: 我们在使用诸如String str = "abc";的格式定义类时,总是想当然地认为,创建了String类的对象str。担心陷阱!对象可能并没有被创建!而可能只是指向一个先前已经创建的对象。只有通过new()方法才能保证每次都创建一个新的对象。

由于String类的immutable性质,当String变量需要经常变换其值时,应该考虑使用StringBuffer类,以提高程序效率。

 

 

2、JAVA中StringBuffer与StringBuilder、String的区别是什么?

String 是字符串类 最常用于简单的字符串操作

StringBuffer 是字符串缓冲。 适用于复杂的字符串增删改操作。
StringBuilder 是与 StringBuffer 兼容的 API 简化。 该类被设计用作 StringBuffer 的一个简易替换,用在字符串缓冲区被单个线程使用的时候(这种情况很普遍)。
String每个新的变量都会分配新的空间,拼接字符串的时候不建议使用。
StringBuffer 用于拼接字符串,支持append、insert方法,内存空间会自己扩展,不需要额外分配,效率较高,线程安全。
StringBuilder 和StringBuffer类似,区别是他线程不安全,所以单线程情况下它效率更高。若在多线程环境下,请使用StringBuffer。

 

3、GC是java的垃圾回收

几种实现的方法

 <wbr><wbr>1、 引用计数法(Reference Counting Collector)<wbr><wbr><br><br>   引用计数法是唯一没有使用根集的垃圾回收的法,该算法使用引用计数器来区分存活对象和不再使用的对象。一般来说,堆中的每个对象对应一个引用计数器。当每一次创建一个对象并赋给一个变量时,引用计数器置为1。当对象被赋给任意变量时,引用计数器每次加1当对象出了作用域后(该对象丢弃不再使用),引用计数器减1,一旦引用计数器为0,对象就满足了垃圾收集的条件。<wbr><wbr><br><br>   基于引用计数器的垃圾收集器运行较快,不会长时间中断程序执行,适宜地必须实时运行的程序。但引用计数器增加了程序执行的开销,因为每次对象赋给新的变量,计数器加1,而每次现有对象出了作用域生,计数器减1。<wbr><wbr><br><br>   2、tracing算法(Tracing Collector)<wbr><wbr><br><br>   tracing算法是为了解决引用计数法的问题而提出,它使用了根集的概念。基于tracing算法的垃圾收集器从根集开始扫描,识别出哪些对象可达,哪些对象不可达,并用某种方式标记可达对象,例如对每个可达对象设置一个或多个位。在扫描识别过程中,基于tracing算法的垃圾收集也称为标记和清除(mark-and-sweep)垃圾收集器.<wbr><wbr><br><br>   3、compacting算法(Compacting Collector)<wbr><wbr><br><br>   为了解决堆碎片问题,基于tracing的垃圾回收吸收了Compacting算法的思想,在清除的过程中,算法将所有的对象移到堆的一端,堆的另一端就变成了一个相邻的空闲内存区,收集器会对它移动的所有对象的所有引用进行更新,使得这些引用在新的位置能识别原来的对象。在基于Compacting算法的收集器的实现中,一般增加句柄和句柄表。<wbr><wbr><br><br>   4、copying算法(Coping Collector)<wbr><wbr><br><br>   该算法的提出是为了克服句柄的开销和解决堆碎片的垃圾回收。它开始时把堆分成 一个对象面和多个空闲面,程序从对象面为对象分配空间,当对象满了,基于coping算法的垃圾收集就从根集中扫描活动对象,并将每个活动对象复制到空闲面(使得活动对象所占的内存之间没有空闲洞),这样空闲面变成了对象面,原来的对象面变成了空闲面,程序会在新的对象面中分配内存。<wbr><wbr><br><br>   一种典型的基于coping算法的垃圾回收是stop-and-copy算法,它将堆分成对象面和空闲区域面,在对象面与空闲区域面的切换过程中,程序暂停执行。<wbr><wbr><br><br>   5、generation算法(Generational Collector)<wbr><wbr><br><br>   stop-and-copy垃圾收集器的一个缺陷是收集器必须复制所有的活动对象,这增加了程序等待时间,这是coping算法低效的原因。在程序设计中有这样的规律:多数对象存在的时间比较短,少数的存在时间比较长。因此,generation算法将堆分成两个或多个,每个子堆作为对象的一代(generation)。由于多数对象存在的时间比较短,随着程序丢弃不使用的对象,垃圾收集器将从最年轻的子堆中收集这些对象。在分代式的垃圾收集器运行后,上次运行存活下来的对象移到下一最高代的子堆中,由于老一代的子堆不会经常被回收,因而节省了时间。<wbr><wbr><br><br>   6、adaptive算法(Adaptive Collector)<wbr><wbr><br><br>   在特定的情况下,一些垃圾收集算法会优于其它算法。基于Adaptive算法的垃圾收集器就是监控当前堆的使用情况,并将选择适当算法的垃圾收集器。<wbr><wbr><br> 透视Java垃圾回收<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

 

4.简述 Java Server Page 和 Servlet 的联系和区别。

Servlet是一种在服务器端运行的Java程序,从某种意义上说,它就是服务器端的Applet。所以Servlet可以像Applet一样作为一种 插件(Plugin)嵌入到Web Server中去,提供诸如HTTP、FTP等协议服务甚至用户自已定制的协议服务。而JSP是继Servlet后Sun公司推出的新技术,它是以 Servlet为基础开发的,Servlet与JSP区别:

(1)编程方式不同 JSP是为了解决Servlet中相对困难的编程技术而开发的技术,因此,JSP在程序的编写方面比Servlet要容易的多,Servlet严格遵循Java语言的编程标准,而JSP则遵循脚本语言的编制标准。

(2)Servlet必须在编译以后才能执行 JSP并不需要另外进行编译,JSP Container会自动完成这一工作,而Servlet在每次修改代码之后都需要编译完才能执行。

(3)运行速度不同

由于JSP Container将JSP程序编译成Servlet的时候需要一些时间,所以JSP的运行速度比Servlet要慢一些,不过,如果JSP文件能毫无变 化的重复使用,它在第一次以后的调用中运行速度就会和Servlet一样了,这是因为JSP Container接到请求以后会确认传递过来的JSP是否有改动,如果没有改动的话,将直接调用JSP编译过的Servlet类,并提供给客户端解释执 行,如果JSP文件有所改变,JSP Container将重新将它编译成Servlet,然后再提交给客户端

 

5、Collection 和 Collections的区别。

 

Collections是个java.util下的类,它包含有各种有关集合操作的静态方法。 
Collection是个java.util下的接口,它是各种集合结构的父接口。 
List, Set, Map是否继承自Collection接口? List,Set是  Map不是
ArrayList和Vector的区别。 
一.同步性:Vector是线程安全的,也就是说是同步的,而ArrayList是线程序不安全的,不是同步的 
二.数据增长:当需要增长时,Vector默认增长为原来一培,而ArrayList却是原来的一半
HashMap和Hashtable的区别 
一.历史原因:Hashtable是基于陈旧的Dictionary类的,HashMap是Java 1.2引进的Map接口的一个实现 
二.同步性:Hashtable是线程安全的,也就是说是同步的,而HashMap是线程序不安全的,不是同步的 
三.值:只有HashMap可以让你将空值作为一个表的条目的key或value 

 

6、abstract class和interface有什么区别?

 

声明方法的存在而不去实现它的类被叫做抽象类(abstract class),它用于要创建一个体现某些基本行为的类,并为该类声明方法,但不能在该类中实现该类的情况。不能创建abstract 类的实例。然而可以创建一个变量,其类型是一个抽象类,并让它指向具体子类的一个实例。不能有抽象构造函数或抽象静态方法。Abstract 类的子类为它们父类中的所有抽象方法提供实现,否则它们也是抽象类为。取而代之,在子类中实现该方法。知道其行为的其它类可以在类中实现这些方法。
接口(interface)是抽象类的变体。在接口中,所有方法都是抽象的。多继承性可通过实现这样的接口而获得。接口中的所有方法都是抽象的,没有一个有程序体。接口只可以定义static final成员变量。接口的实现与子类相似,除了该实现类不能从接口定义中继承行为。当类实现特殊接口时,它定义(即将程序体给予)所有这种接口的方法。然后,它可以在实现了该接口的类的任何对象上调用接口的方法。由于有抽象类,它允许使用接口名作为引用变量的类型。通常的动态联编将生效。引用可以转换到接口类型或从接口类型转换,instanceof 运算符可以用来决定某对象的类是否实现了接口。
抽象类:
 |-由抽象方法和常量、变量、全局常量、构造方法、普通方法组成
 |-使用abstract声明
 |-子类要通过extends继承抽象类,子类如果不是抽象类,则必须覆写抽象类的全部抽象方法
 |-存在单继承的局限
 |-抽象类可以实现若干个接口
接口:
 |-由抽象方法和全局常量组成
 |-使用interface关键字
 |-子类要通过implements实现接口,子类如果不是抽象类,则必须覆写抽象类的全部抽象方法
 |-一个子类可以实现多个接口
 |-接口不能继承一个抽象类,但允许继承多个接口

 

7、sleep() 和 wait() 有什么区别?

sleep是线程类(Thread)的方法,导致此线程暂停执行指定时间,给执行机会给其他线程,但是监控状态依然保持,到时后会自动恢复。调用sleep不会释放对象锁。

wait是Object类的方法,对此对象调用wait方法导致本线程放弃对象锁,进入等待此对象的等待锁定池,只有针对此对象发出notify方法(或notifyAll)后本线程才进入对象锁定池准备获得对象锁进入运行状态。
8、Java Servlet API中forward() 与redirect()的区别
forward是服务器请求资源,服务器直接访问目标地址的URL,把那个URL的响应内容读取过来,然后把这些内容再发给浏览器,浏览器根本不知道服务 器发送的内容是从哪儿来的,所以它的地址栏中还是原来的地址。还有,转发是在web应用程序之内进行的,可以访问web应用程序所设定的内部目录,像是 WEB-INF目录,只能在Web应用程序中进行,不能指定至其它的Web应用程序的地址。
redirect就是服务端根据逻辑,发送一个状态码,告诉浏览器重新去请求那个地址,一般来说浏览器会用刚才请求的所有参数重新请求,所以 session,request参数都可以获取。web应用程序会要求客户端浏览器重新发出请求地址,客户端会重新连接至所指定的地址,因此浏览器的地址 会出现重新导向的信息,重新导向后的请求由浏览器发出,所以不能访问Web应用程序中的隐藏目录,像是WEB-INF,重新是由浏览器重新要求一个网页, 可以指定至其他的Web应用程序地址。
RequestDispatcher.forward()方法和HttpServletResponse.sendRedirect() 方法的区别是:前者仅是容器中控制权的转向,在客户端浏览器地址栏中不会显示出转向后的地址,他是不会改变Request的值,如果你需要在下一个页面中 能从中获取新的信息的话,你可以Request.setAttribute()来放置一些标志,这样从下一个页面中获取;后者则是完全的跳转,浏览器将会 得到跳转的地址,并重新发送请求链接。这样,从浏览器的地址栏中可以看到跳转后的链接地址。所以,前者更加高效,在前者可以满足需要时,尽量使用 Request Dispatcher.forward()方法,并且,这样也有助于隐藏实际的链接。在有些情况下,比如,需要跳转到一个其它服务器上的资源,则必须使用 HttpServletResponse.sendRequest()方法。
1、forward与include共亨Request范围内的对象,而redirect则不行,即:如果一个javabean被声明为request范围的话,则被forward到的资源也可以访问这个javabean,而redriect则不行。
2、forward与include基本上都是转发到context内部的资源,而redirect可以重定向到外部的资源,如: req.sendRedriect

1.从地址栏显示来说
forward是服务器请求资源,服务器直接访问目标地址的URL,把那个URL的响应内容读取过来,然后把这些内容再发给浏览器.浏览器根本不知道服务器发送的内容从哪里来的,所以它的地址栏还是原来的地址.
redirect是服务端根据逻辑,发送一个状态码,告诉浏览器重新去请求那个地址.所以地址栏显示的是新的URL.
2.从数据共享来说
forward:转发页面和转发到的页面可以共享request里面的数据.
redirect:不能共享数据.
3.从运用地方来说
forward:一般用于用户登陆的时候,根据角色转发到相应的模块.
redirect:一般用于用户注销登陆时返回主页面和跳转到其它的网站等.
4.从效率来说
forward:高.
redirect:低.

这是我在网上找到的资料,本来我以为我知道他们的区别,认为主要是当前的请求变量是否继续有效,但看了这个,了解了请求的作用范围,才完全明白其中的原因,希望对大家有用。
不要仅仅为了把变量传到下一个页面而使用session作用域,那会无故增大变量的作用域,转发也许可以帮助你解决这个问题。
重定向:以前的request中存放的变量全部失效,并进入一个新的request作用域。
转发:以前的request中存放的变量不会失效,就像把两个页面拼到了一起。
正文开始:
先是看上去不同,他们的调用分别如下:
request.getRequestDispatcher("apage.jsp").forward(request, response);//转发到apage.jsp
response.sendRedirect("apage.jsp");//重定向到apage.jsp
在jsp页面中你也会看到通过下面的方式实现转发:
<jsp:forward page="apage.jsp" />
提到转发和重定向就不得不提到request作用域。很多初学者都知道当我们提交一个表单时,就创建了一个新的请求。实际上,当我们点击一个链接时,也创建了一个新的请求。那么一个请求的作用域到底有多大呢?例如:
在页面a.jsp中有一个链接<a href="b.jsp?id=1">这是指向b的一个链接,而且还带了一个参数</a>。当我们点击这个连接的时候,就产生了一个请 求,为了明确起见,我们把它叫做requestA->B。现在,在b.jsp页面中我们就可以从这个请求中获取信息了。在b.jsp中你可以写入 out.println(request.getParameter("id"))进行测试。下面更复杂一点,我们在b.jsp页面中增加下面的语句:
request.setAttribute("name","funcreal");
out.println(request.getAttriblute("name"));//成功显示了name变量的值。
现在在b.jsp中再增加一个链接:<a href="c.jsp?age=23">这是指向c的一个链接,而且还带了一个参数</a>,当我们点击这个连接的时候,将产生一个 新的请求,这时requestA-B也就安息了,新的请求叫做requestB-C。同样的道理,在c.jsp中,我们可以访问到的变量只有age,因为 id,name这两个变量都属于requestA-B,此时他已经不存在了。下面是源代码:
a.jsp
<%@ page c %>
<html>
<body bgcolor="#ffffff">
<a href="b.jsp?id=1">指向b.jsp,而且还带了一个参数id=1。requestA-B现在诞生了</a>
</body>
</html>
b.jsp
<%@ page c %>
<html>
<body bgcolor="#ffffff">
<%
out.println("id=" + request.getParameter("id"));
request.setAttribute("name","Func Real");
out.println("name=" + request.getAttribute("name"));
%>
<a href="c.jsp?age=23">requestA-B已经结束了。指向c.jsp,而且还带了一个参数age=23</a>
</body>
</html>
c.jsp
<%@ page c %>
<html>
<body bgcolor="#ffffff">
<%
out.println("id=" + request.getParameter("id"));
out.println("name=" + request.getAttribute("name"));
out.println("age=" + request.getParameter("age"));
%>
</body>
</html>
那么转发又是怎么回事呢?现在增加一个页面叫做d.jsp,并且在c.jsp中</body>前面增加一句<jsp:forward page="d.jsp"/>
d.jsp
<%@ page c %>
<html>
<body bgcolor="#ffffff">
requestB-C的魔爪已经伸到了d.jsp页面
<%
out.println("age=" + request.getParameter("age"));
%>
</body>
</html>
运行程序,你会发现c页面中的内容没有显示出来,因为forward是自动执行的,地址栏中虽然是c.jsp但实际上,但浏览器中显示的已经是d.jsp 的内容了,而且看到了从b.jsp传过来的参数。你可以简单得这样理解:转发,就是延长了requestB-C的作用域,<jsp:forward page="d.jsp"/>,这一句话实际上是把c.jsp和d.jsp粘到了一起,他们就像是在一个页面中。
如果你用过struts,那么你就知道为什么在Action中,最后一句几乎总是mapping.findForward("xxx");了。因为我们在这个Action中设置的请求作用域的变量都将会在下一个页面(也许是另一个Action)中用到,所以要用转发。
总结:
用重定向和转发不是一个习惯问题。而是什么情况下必须用什么的问题。
不要仅仅为了把变量传到下一个页面而使用session作用域,那会无故增大变量的作用域,转发也许可以帮助你解决这个问题。
重定向:以前的request中存放的变量全部失效,并进入一个新的request作用域。
转发:以前的request中存放的变量不会失效,就像把两个页面拼到了一起。
forward是服务器请求资源,服务器直接访问目标地址的URL,把那个URL的响应内容读取过来,然后把这些内容再发给浏览器,浏览器根本不知道服务器发送的内容是从哪儿来的,所以它的地址栏中还是原来的地址。
redirect就是服务端根据逻辑,发送一个状态码,告诉浏览器重新去请求那个地址, web应用程序会要求客户端浏览器重新发出请求地址,客户端会重新连接至所指定的地址,因此浏览器的地址会出现重新导向的信息,重新导向后的请求由浏览器发出。
forward与include共享Request范围内的对象,而redirect则不行,
forward与include基本上都是转发到context内部的资源,而redirect可以重定向到外部的资源
9、Servlet的生命周期
1,初始化阶段  调用init()方法

2,响应客户请求阶段  调用service()方法

3,终止阶段  调用destroy()方法
10、简述AWT中事件处理机制
当事件源发生事件时,就会自动调用该事件的接口方法,而方法中就是编写的事件处理程序代码。
要实现AWT中事件处理,需以下三步:
1,事件源
      能够产生事件的对象都可以成为事件源,如文本框,按钮等。也就是说,事件源必须是一个对象,而且这个对象必须是Java认为能够发生时间的对象。
2,监视器
      需要一个对象对事件源进行监视,以便对发生的事件作出处理。
例如:对于文本框,这个方法为:addActionListener(监视器);
3,处理事件的接口
      监视器负责处理事件源发生的事件。为了让监视器这个对象能对事件源发生的事件进行处理,创建该监视器对象的类必须申明实现相应的接口,即必须在类体中给出该接口中的所有方法体,那么当事件源发生事件时,监视器就自动调用类实现的某个接口方法。
11、session、cookie和cache的区别是什么?
解释一:
session和cookies是保存每个用户单独的信息,前者保存在服务器。安全。后者保存在客户端。安全比较低。后者可以长期保存。 <wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><br style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">cache是缓存。所有用户都可以访问到的对象。保存在服务器</span><br style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">解释二:</span><br style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">session </span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">信息存于服务端,在交互时传到客户端一个sessionid,客户端请求数据时发送sessionid用于识别 </span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><br style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">cookies </span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">信息存于客户端,在效互时客户端将信息发送至服务端,安全性较差. </span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><br style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">cache用于缓冲数据,通常为网页及媒体文件,在涉及安全性的动态生成页面上,可以设置有较时间,以便减少攻击</span><br style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">解释三:</span><br style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">一般session的默认生命周期是20分钟,也就是说如果你在20分钟里没有发送任何请求的话,session就过期了。 </span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">在 </span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">web.config </span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">文件里面设置: </span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><br style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">&lt;sessionState </span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><br style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">mode="InProc" </span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><br style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">stateConnectionString="tcpip=127.0.0.1:42424" </span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><br style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">sqlConnectionString="data </span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">source=127.0.0.1;Trusted_Connection=yes" </span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><br style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">cookieless="false" </span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><br style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">timeout="20" </span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><br style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">/&gt;</span><br style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">cache不可靠,会随时被根据系统要求而清除,但是自动管理过期时间和依赖,名副其实地是缓存的作用。 </span><wbr style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><br style="color:rgb(70,70,70); font-family:simsun; line-height:21px"><span style="color:rgb(70,70,70); font-family:simsun; line-height:21px">cookie会在客户端浏览器和服务器之间来回丢来丢去,是最原始的保存用户信息的形式,对加密、性能等都无从考虑(当然在这个系统上扩展以后可以达到),并且浏览器对其大小限制得很紧。</span> </wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

session是存在服务器的内存中 每个会话对应一个sessionId 通过sessionId开区分是那个会话的session,是以键值对的形式存储

如果有几千个session,怎么提高效率?
几千个session,怎么提高效率,可以依靠Cookies几千个session并不多,关键看session里面装了些什么,session里面只存储用户索引id就可以了。存几万个int也无所谓。
将全站的session内容做个统计,将所有相关的部分,规划成对象,然后在session里储存实例。
这样可以有效的减少session数量,提高使用和维护效率。

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics