发表于: 2017-05-13 23:47:15
1 1024
1.早上听老大讲了分布式,遇到性能瓶颈的时候可以横向扩展。新加入的service怎么能知道是否可以提供服务呢:(1)登记在表中,home每隔一段时间查询一次(2)home每隔一段时间扫描,查询端口号,相应的端口号是可用的便加上服务
nginx的upstream负载均衡,,,如果服务器挂点怎么处理:抛异常,手动处理
scallop 作为负载均衡(web--service) resources --- name / 服务 ---地址
2.下午讲了高并发时使用给缓存,memcached:service取值先到缓存中取,如果没有,需要到数据库中取,取到值之后将值存到缓存中,服务器开启缓存开启,一旦服务器关闭,缓存中存储的数据也会随之清除,在服务器出现问题时,要先更新数据库再来更新缓存,不然会出现脏数据。。
DAL作用:把缓存需要做的(增删改查需要对缓存的操作)对缓存的操作封装到dal中
DAL原则:单表;简单语句,没有order by;一对一
DAL三种缓存:list、map缓存(忘记了一个)
以上都是模糊记忆。。待验证。。
(3)用sql语句的limit进行分条查询,每次查询一个页面的条数,并通过sql语句select count(*) from .... 获取总条数,将总条数除以每页条数,的到一个除数,一个余数,这个除数+1就是分页的总共有多少页,余数便是用来判断是否有下一页。,没电下一个就会进入数据库取下页的条数。
public class UserDao {
/**
* 计算总的页数
*
* @return
*/
public int getPage() {
int recordCount = 0, t1 = 0, t2 = 0;
PreparedStatement pstmt = null;
ResultSet result = null;
JDBCUtils jdbc = new JDBCUtils();
Connection conn = jdbc.connect();
String sql = "select count(*) from user";
try {
pstmt = conn.prepareStatement(sql);
result = pstmt.executeQuery();
result.next();
recordCount = result.getInt(1);
t1 = recordCount % 5;
t2 = recordCount / 5;
} catch (Exception e) {
e.printStackTrace();
} finally {
jdbc.close(conn, pstmt, result);
}
if (t1 != 0) {
t2 = t2 + 1;
}
return t2;
}
/**
* 查询指定页的数据
*
* @param pageNo
* @return
*/
public List<User> listUser(int pageNo) {
PreparedStatement pstmt = null;
ResultSet result = null;
List<User> list = new ArrayList<User>();
int pageSize = 5;
int page = (pageNo - 1) * 5;
JDBCUtils jdbc = new JDBCUtils();
Connection conn = jdbc.connect();
String sql = "select * from user order by id limit ?,?";
try {
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, page);
pstmt.setInt(2, pageSize);
result = pstmt.executeQuery();
while (result.next()) {
User user = new User();
user.setId(result.getInt(1));
user.setName(result.getString(2));
user.setNumber(result.getString(3));
list.add(user);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
jdbc.close(conn, pstmt, result);
}
return list;
}
}
明天计划的事情:
完成任务六,开始任务七

还在改bug,听师兄说不能挖坑了。。
评论