重写ResultSet实现分页功能(最好的分页技术)(转)

摘要:
importjava.io.Reader;“用户”);此.rs=rs;//calculatePageCount doubletmpD=(double)rowsCount/pageSize;如果(tmpD>=getPageCount())returnpageSize;}publicintgetPageSize(){returnpageSize;

1.首先定义一个接口Pageable 继承ResultSet这个类

并在接口中定义一些自己的方法,具体方法如下:

 package com.page;

import java.sql.ResultSet;

public interface Pageable extends ResultSet {
 
 
 /**返回总页数
 */
 int getPageCount();
 /**返回当前页的记录条数
 */
 int getPageRowsCount();
 /**返回分页大小
 */
 int getPageSize();
 /**转到指定页
 */
 void gotoPage(int page) ;
 /**设置分页大小
 */
 void setPageSize(int pageSize);
 /**返回总记录行数
 */
 int getRowsCount();
 /**
 * 转到当前页的第一条记录
 * @exception java.sql.SQLException 异常说明。
 */
 void pageFirst() throws java.sql.SQLException;
 /**
 * 转到当前页的最后一条记录
 * @exception java.sql.SQLException 异常说明。
 */
 void pageLast() throws java.sql.SQLException;
 /**返回当前页号
 */
 int getCurPage();
 
 

}

2.然后定义一个类PageableResultSet 实现这个接口,覆盖ResultSet的所有方法.并实现接口Pageable 中自定义的方法,具体实现方式如下:

package com.page;

import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
import java.sql.Ref;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Map;

public class PageableResultSet implements Pageable {

 protected java.sql.ResultSet rs=null;
 protected int rowsCount;
 protected int pageSize;
 protected int curPage;
 protected String command = "";

 
 public PageableResultSet(java.sql.ResultSet rs) throws java.sql.SQLException {
  if(rs==null) throw new SQLException("given ResultSet is NULL","user");
  rs.last();
  rowsCount=rs.getRow();
  System.out.println(rowsCount);
  rs.beforeFirst();
  this.rs=rs;

 }
 public int getCurPage() {
  return curPage;
 }

 public int getPageCount() {
  if(rowsCount==0) return 0;
  if(pageSize==0) return 1;
//  calculate PageCount
  double tmpD=(double)rowsCount/pageSize;
  int tmpI=(int)tmpD;
  if(tmpD>tmpI) tmpI++;
  return tmpI;
 }

 public int getPageRowsCount() {
  if(pageSize==0) return rowsCount;
  if(getRowsCount()==0) return 0;
  if(curPage!=getPageCount()) return pageSize;
  return rowsCount-(getPageCount()-1)*pageSize;
 }

 public int getPageSize() {
  return pageSize;
 }

 public int getRowsCount() {
  return rowsCount;
 }

 public void gotoPage(int page) {
  if (rs == null)
   return;
   if (page < 1)
   page = 1;
   if (page > getPageCount())
   page = getPageCount();
   int row = (page - 1) * pageSize + 1;
   try {
   rs.absolute(row);
   curPage = page;
   }
   catch (java.sql.SQLException e) {
   }


 }

 public void pageFirst() throws SQLException {
  int row=(curPage-1)*pageSize+1;
  rs.absolute(row);

 }

 public void pageLast() throws SQLException {
  int row=(curPage-1)*pageSize+getPageRowsCount();
  rs.absolute(row);


 }

 public void setPageSize(int pageSize) {
  if(pageSize>=0){
   this.pageSize=pageSize;
   curPage=1;
   }


 }

 public boolean next() throws SQLException {
  return rs.next();
 }

 public boolean absolute(int row) throws SQLException {
  return rs.absolute(row);
 }

 public void afterLast() throws SQLException {
  rs.afterLast();
  
 }

 public void beforeFirst() throws SQLException {
  rs.beforeFirst();
  
 }

 public void cancelRowUpdates() throws SQLException {
  rs.cancelRowUpdates();
 }

 public void clearWarnings() throws SQLException {
  rs.clearWarnings();
  
 }

 public void close() throws SQLException {
  rs.close();
  
 }

 public void deleteRow() throws SQLException {
  rs.deleteRow();
  
 }

 public int findColumn(String columnName) throws SQLException {
  return rs.findColumn(columnName);
 }

 public boolean first() throws SQLException {
  return rs.first();
 }

 public Array getArray(int i) throws SQLException {
  return rs.getArray(i);
 }

 public Array getArray(String colName) throws SQLException {
  return rs.getArray(colName);
 }

 public InputStream getAsciiStream(int columnIndex) throws SQLException {
  return rs.getAsciiStream(columnIndex);
 }

 public InputStream getAsciiStream(String columnName) throws SQLException {
  return rs.getAsciiStream(columnName);
 }

 public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
  return rs.getBigDecimal(columnIndex);
 }

 public BigDecimal getBigDecimal(String columnName) throws SQLException {
  return rs.getBigDecimal(columnName);
 }

 public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
  return rs.getBigDecimal(columnIndex, scale);
 }

 public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
  return rs.getBigDecimal(columnName, scale);
 }

 public InputStream getBinaryStream(int columnIndex) throws SQLException {
  return rs.getBinaryStream(columnIndex);
 }

 public InputStream getBinaryStream(String columnName) throws SQLException {
  return rs.getBinaryStream(columnName);
 }

 public Blob getBlob(int i) throws SQLException {
  return rs.getBlob(i);
 }

 public Blob getBlob(String colName) throws SQLException {
  return rs.getBlob(colName);
 }

 public boolean getBoolean(int columnIndex) throws SQLException {
  return rs.getBoolean(columnIndex);
 }

 public boolean getBoolean(String columnName) throws SQLException {
  return rs.getBoolean(columnName);
 }

 public byte getByte(int columnIndex) throws SQLException {
  return rs.getByte(columnIndex);
 }

 public byte getByte(String columnName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getByte(columnName);
 }

 public byte[] getBytes(int columnIndex) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getBytes(columnIndex);
 }

 public byte[] getBytes(String columnName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getBytes(columnName);
 }

 public Reader getCharacterStream(int columnIndex) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getCharacterStream(columnIndex);
 }

 public Reader getCharacterStream(String columnName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getCharacterStream(columnName);
 }

 public Clob getClob(int i) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getClob(i);
 }

 public Clob getClob(String colName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getClob(colName);
 }

 public int getConcurrency() throws SQLException {
  // TODO 自动生成方法存根
  return rs.getConcurrency();
 }

 public String getCursorName() throws SQLException {
  // TODO 自动生成方法存根
  return rs.getCursorName();
 }

 public Date getDate(int columnIndex) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getDate(columnIndex);
 }

 public Date getDate(String columnName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getDate(columnName);
 }

 public Date getDate(int columnIndex, Calendar cal) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getDate(columnIndex, cal);
 }

 public Date getDate(String columnName, Calendar cal) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getDate(columnName, cal);
 }

 public double getDouble(int columnIndex) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getDouble(columnIndex);
 }

 public double getDouble(String columnName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getDouble(columnName);
 }

 public int getFetchDirection() throws SQLException {
  // TODO 自动生成方法存根
  return rs.getFetchDirection();
 }

 public int getFetchSize() throws SQLException {
  // TODO 自动生成方法存根
  return rs.getFetchSize();
 }

 public float getFloat(int columnIndex) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getFloat(columnIndex);
 }

 public float getFloat(String columnName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getFloat(columnName);
 }

 public int getInt(int columnIndex) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getInt(columnIndex);
 }

 public int getInt(String columnName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getInt(columnName);
 }

 public long getLong(int columnIndex) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getLong(columnIndex);
 }

 public long getLong(String columnName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getLong(columnName);
 }

 public ResultSetMetaData getMetaData() throws SQLException {
  // TODO 自动生成方法存根
  return rs.getMetaData();
 }

 public Object getObject(int columnIndex) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getObject(columnIndex);
 }

 public Object getObject(String columnName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getObject(columnName);
 }

 public Object getObject(int i, Map<String, Class<?>> map) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getObject(i, map);
 }

 public Object getObject(String colName, Map<String, Class<?>> map) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getObject(colName, map);
 }

 public Ref getRef(int i) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getRef(i);
 }

 public Ref getRef(String colName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getRef(colName);
 }

 public int getRow() throws SQLException {
  // TODO 自动生成方法存根
  return rs.getRow();
 }

 public short getShort(int columnIndex) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getShort(columnIndex);
 }

 public short getShort(String columnName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getShort(columnName);
 }

 public Statement getStatement() throws SQLException {
  // TODO 自动生成方法存根
  return rs.getStatement();
 }

 public String getString(int columnIndex) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getString(columnIndex);
 }

 public String getString(String columnName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getString(columnName);
 }

 public Time getTime(int columnIndex) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getTime(columnIndex);
 }

 public Time getTime(String columnName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getTime(columnName);
 }

 public Time getTime(int columnIndex, Calendar cal) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getTime(columnIndex, cal);
 }

 public Time getTime(String columnName, Calendar cal) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getTime(columnName, cal);
 }

 public Timestamp getTimestamp(int columnIndex) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getTimestamp(columnIndex);
 }

 public Timestamp getTimestamp(String columnName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getTimestamp(columnName);
 }

 public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getTimestamp(columnIndex, cal);
 }

 public Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getTimestamp(columnName, cal);
 }

 public int getType() throws SQLException {
  // TODO 自动生成方法存根
  return rs.getType();
 }

 public URL getURL(int columnIndex) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getURL(columnIndex);
 }

 public URL getURL(String columnName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getURL(columnName);
 }

 public InputStream getUnicodeStream(int columnIndex) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getUnicodeStream(columnIndex);
 }

 public InputStream getUnicodeStream(String columnName) throws SQLException {
  // TODO 自动生成方法存根
  return rs.getUnicodeStream(columnName);
 }

 public SQLWarning getWarnings() throws SQLException {
  // TODO 自动生成方法存根
  return rs.getWarnings();
 }

 public void insertRow() throws SQLException {
  // TODO 自动生成方法存根
  rs.insertRow();
  
 }

 public boolean isAfterLast() throws SQLException {
  // TODO 自动生成方法存根
  return rs.isAfterLast();
 }

 public boolean isBeforeFirst() throws SQLException {
  // TODO 自动生成方法存根
  return rs.isBeforeFirst();
 }

 public boolean isFirst() throws SQLException {
  // TODO 自动生成方法存根
  return rs.isFirst();
 }

 public boolean isLast() throws SQLException {
  // TODO 自动生成方法存根
  return rs.isLast();
 }

 public boolean last() throws SQLException {
  // TODO 自动生成方法存根
  return rs.last();
 }

 public void moveToCurrentRow() throws SQLException {
  // TODO 自动生成方法存根
  rs.moveToCurrentRow();
 }

 public void moveToInsertRow() throws SQLException {
  // TODO 自动生成方法存根
  rs.moveToInsertRow();
 }

 public boolean previous() throws SQLException {
  // TODO 自动生成方法存根
  return rs.previous();
 }

 public void refreshRow() throws SQLException {
  // TODO 自动生成方法存根
  rs.refreshRow();
 }

 public boolean relative(int rows) throws SQLException {
  // TODO 自动生成方法存根
  return rs.relative(rows);
 }

 public boolean rowDeleted() throws SQLException {
  // TODO 自动生成方法存根
  return rs.rowDeleted();
 }

 public boolean rowInserted() throws SQLException {
  // TODO 自动生成方法存根
  return rs.rowInserted();
 }

 public boolean rowUpdated() throws SQLException {
  // TODO 自动生成方法存根
  return rs.rowUpdated();
 }

 public void setFetchDirection(int direction) throws SQLException {
  // TODO 自动生成方法存根
  rs.setFetchDirection(direction);
 }

 public void setFetchSize(int rows) throws SQLException {
  // TODO 自动生成方法存根
  rs.setFetchSize(rows);
 }

 public void updateArray(int columnIndex, Array x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateArray(columnIndex, x);
 }

 public void updateArray(String columnName, Array x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateArray(columnName, x);
 }

 public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateAsciiStream(columnIndex, x, length);
 }

 public void updateAsciiStream(String columnName, InputStream x, int length) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateAsciiStream(columnName, x, length);
 }

 public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateBigDecimal(columnIndex, x);
 }

 public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateBigDecimal(columnName, x);
 }

 public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateBinaryStream(columnIndex, x, length);
 }

 public void updateBinaryStream(String columnName, InputStream x, int length) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateBinaryStream(columnName, x, length);
 }

 public void updateBlob(int columnIndex, Blob x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateBlob(columnIndex, x);
 }

 public void updateBlob(String columnName, Blob x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateBlob(columnName, x);
 }

 public void updateBoolean(int columnIndex, boolean x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateBoolean(columnIndex, x);
 }

 public void updateBoolean(String columnName, boolean x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateBoolean(columnName, x);
 }

 public void updateByte(int columnIndex, byte x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateByte(columnIndex, x);
 }

 public void updateByte(String columnName, byte x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateByte(columnName, x);
 }

 public void updateBytes(int columnIndex, byte[] x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateBytes(columnIndex, x);
 }

 public void updateBytes(String columnName, byte[] x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateBytes(columnName, x);
 }

 public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateCharacterStream(columnIndex, x, length);
 }

 public void updateCharacterStream(String columnName, Reader reader, int length) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateCharacterStream(columnName, reader, length);
 }

 public void updateClob(int columnIndex, Clob x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateClob(columnIndex, x); 
 }

 public void updateClob(String columnName, Clob x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateClob(columnName, x);  
 }

 public void updateDate(int columnIndex, Date x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateDate(columnIndex, x);
 }

 public void updateDate(String columnName, Date x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateDate(columnName, x);
 }

 public void updateDouble(int columnIndex, double x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateDouble(columnIndex, x); 
 }

 public void updateDouble(String columnName, double x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateDouble(columnName, x);
 }

 public void updateFloat(int columnIndex, float x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateFloat(columnIndex, x);
 }

 public void updateFloat(String columnName, float x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateFloat(columnName, x);
 }

 public void updateInt(int columnIndex, int x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateInt(columnIndex, x);
 }

 public void updateInt(String columnName, int x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateInt(columnName, x);
 }

 public void updateLong(int columnIndex, long x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateLong(columnIndex, x);
 }

 public void updateLong(String columnName, long x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateLong(columnName, x);
 }

 public void updateNull(int columnIndex) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateNull(columnIndex);
 }

 public void updateNull(String columnName) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateNull(columnName);
 }

 public void updateObject(int columnIndex, Object x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateObject(columnIndex, x);
 }

 public void updateObject(String columnName, Object x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateObject(columnName, x);
 }

 public void updateObject(int columnIndex, Object x, int scale) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateObject(columnIndex, x, scale);
 }

 public void updateObject(String columnName, Object x, int scale) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateObject(columnName, x, scale);
 }

 public void updateRef(int columnIndex, Ref x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateRef(columnIndex, x);
 }

 public void updateRef(String columnName, Ref x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateRef(columnName, x);
 }

 public void updateRow() throws SQLException {
  // TODO 自动生成方法存根
  rs.updateRow();
 }

 public void updateShort(int columnIndex, short x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateShort(columnIndex, x);
 }

 public void updateShort(String columnName, short x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateShort(columnName, x);
 }

 public void updateString(int columnIndex, String x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateString(columnIndex, x);
 }

 public void updateString(String columnName, String x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateString(columnName, x);
 }

 public void updateTime(int columnIndex, Time x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateTime(columnIndex, x);
 }

 public void updateTime(String columnName, Time x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateTime(columnName, x);
 }

 public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateTimestamp(columnIndex, x);
 }

 public void updateTimestamp(String columnName, Timestamp x) throws SQLException {
  // TODO 自动生成方法存根
  rs.updateTimestamp(columnName, x);
 }

 public boolean wasNull() throws SQLException {
  // TODO 自动生成方法存根
  return rs.wasNull();
 }


}

3.如何运用

获得ResultSet的时候:

pstm=con.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);//这里的属性一定要记得修改

Pageable rs=new PageableResultSet(pstm.executeQuery());//得到ResultSet

4.设置RS

rs.setPageSize(pageSize);//设置每页显示数目
   rs.gotoPage(page);//设置当前选择第几页
   for (int i = 0; i < rs.getPageRowsCount(); i++) {
    /...进行取值.../
    rs.next();//不要忘记next()
   }

http://blog.csdn.net/yangxin114/article/details/1668320

免责声明:文章转载自《重写ResultSet实现分页功能(最好的分页技术)(转)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇SDP(12): MongoDB-Engine一些linux命令行下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Win7 计算机(我的电脑)右键菜单“管理”打不开,解决方法

Win7 计算机(我的电脑)右键菜单“管理”打不开   自从重返校园之后,每天都很多事情要忙,时间被分割成碎片,写博客的念头随之消失了。今天遇到了电脑的管理打不开了,解决方法如下: WIN7计算机(我的电脑)右键“管理”打不开,弹出与之关联的程序找不到,显示错误。这是由于系统默认路径被修改,比如我的文档路径转移到其他分区上,也同样会出现这种情况。下面可以有...

EC20模块(mdm9607)复用pin脚当作普通gpio的设置方法

修改pin37~40,当作普通gpio的方法如下:   下面代码截图需要确认是否一样,如不一样请修改:   修改pin41~42 ,当作普通gpio方法如下:   Pin24~27,当作普通gpio方法如下:         Pin136不建议修改。 Pin136的用法,请参考以下文件/etc/init.d/wlan:  ...

图片上传——用一般处理程序实现

.Net 中如何实现图片上传 1、表单元素使用文件选择框<input  type ="file " />控件2、表单设置enctype="multipart /form-data ",本质上是设置浏览器提交表单的数据时,使用随机分隔符来分 割不同控件的数据,而且数据的组织形势由name=value 换成了数据头和数据体的方式 二、服务器端1、服...

JAVA中GC时finalize()方法是不是一定会被执行?

在回答上面问题之前,我们一定要了解JVM在进行垃圾回收时的机制,首先: 一、可达性算法  要知道对象什么时候死亡,我们需要先知道JVM的GC是如何判断对象是可以回收的。JAVA是通过可达性算法来来判断对象是否存活的。这个算法的基本思路就是通过一系列的称为“GC Roots”的对象作为起始点,从这些节点开始向下搜索,搜索所走过的路径称为引用链,当一个对象到G...

网络爬虫必备知识之requests库

就库的范围,个人认为网络爬虫必备库知识包括urllib、requests、re、BeautifulSoup、concurrent.futures,接下来将结对requests库的使用方法进行总结 1. requests库简介   官方中文文档:http://docs.python-requests.org/zh_CN/latest/user/quickst...

QtDbus的API及示例

目录 1. Client :: Method Call 1.1. 方法1: 直接使用 Message 传递消息(Low-Level-API) 1.2. 方法2: 通过 DBusInterface 调用方法(同步+异步) 1.3. 方法3: 从XML导入代理类 2. Subscriber :: Signal Catching 2.1. 方法1:...