当前位置: 首页 > news >正文

安新建设局网站展示类网站模板js

安新建设局网站,展示类网站模板js,程序员建网站,ui设计培训机构有用吗生成测试用户 将UserUtils工具类导入到zmall-user模块中#xff0c;运行生成测试用户信息#xff0c;可根据自身电脑情况来生成用户数量。 UserUtils#xff1a; package com.xujie.zmall.utils;import com.alibaba.nacos.common.utils.MD5Utils; import com.fasterxml.j…生成测试用户 将UserUtils工具类导入到zmall-user模块中运行生成测试用户信息可根据自身电脑情况来生成用户数量。 UserUtils package com.xujie.zmall.utils;import com.alibaba.nacos.common.utils.MD5Utils; import com.fasterxml.jackson.databind.ObjectMapper; import com.xujie.zmall.model.User; import com.xujie.zmall.util.JsonResponseBody;import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Date; import java.util.List;public class UserUtils {private static void createUser(int count) throws Exception {ListUser lstnew ArrayListUser();//循环添加用户数据for(int i0;icount;i){User usernew User();user.setLoginName(useri);user.setUserName(测试用户i);user.setPassword(MD5Utils.md5Hex(123456.getBytes()));user.setType(0);user.setMobile((17700000000Li));user.setEmail(useri139.com);user.setIdentityCode((430104199912120000Li));lst.add(user);}System.out.println(create users);//获取数据库连接Connection conngetConn();//定义SQLString sqlinsert into zmall_user(loginName,userName,password,identityCode,email,mobile,type) values(?,?,?,?,?,?,?);//执行SQLPreparedStatement psconn.prepareStatement(sql);//赋值for (User user : lst){ps.setString(1,user.getLoginName());ps.setString(2,user.getUserName());ps.setString(3,user.getPassword());ps.setString(4,user.getIdentityCode());ps.setString(5,user.getEmail());ps.setString(6,user.getMobile());ps.setInt(7,user.getType());ps.addBatch();}ps.executeBatch();ps.clearParameters();ps.close();conn.close();System.out.println(insert to db);//登录生成UserTicketString urlStringhttp://localhost:8010/userLogin;File filenew File(C:\\Users\\xj\\DeskTop\\config.txt);if(file.exists()){file.delete();}RandomAccessFile accessFilenew RandomAccessFile(file,rw);//设置光标位置accessFile.seek(0);for (User user : lst) {URL urlnew URL(urlString);HttpURLConnection co (HttpURLConnection) url.openConnection();co.setRequestMethod(POST);co.setDoOutput(true);OutputStream outco.getOutputStream();String paramsloginNameuser.getLoginName()password123456;out.write(params.getBytes());out.flush();InputStream inco.getInputStream();ByteArrayOutputStream boutnew ByteArrayOutputStream();byte[] buffernew byte[1024];int len0;while((lenin.read(buffer))0){bout.write(buffer,0,len);}in.close();bout.close();String responsenew String(bout.toByteArray());ObjectMapper mappernew ObjectMapper();JsonResponseBody jsonResponseBodymapper.readValue(response, JsonResponseBody.class);String tokenjsonResponseBody.getData().toString();System.out.println(create token:token);accessFile.seek(accessFile.length());accessFile.write(token.getBytes());accessFile.write(\r\n.getBytes());//System.out.println(write to file:token);}accessFile.close();System.out.println(over);}private static Connection getConn() throws Exception {String urljdbc:mysql://localhost:3306/zmall?useSSLfalseuseUnicodetrueuseJDBCCompliantTimezoneShifttrueuseLegacyDatetimeCodefalseserverTimezoneUTCcharacterEncodingUTF8;String drivercom.mysql.jdbc.Driver;String usernameroot;String password1234;Class.forName(driver);return DriverManager.getConnection(url,username,password);}public static void main(String[] args) throws Exception {createUser(100);} } 1必须保证zmall-user模块处于运行状态下在进行测试用户数据生成操作 2注意修改UserUtils中的用户登录接口地址及端口同时请修改用户登录接口将生成的token令牌存入响应封装类中 //5.通过UUID生成token令牌并保存到cookie中 String token UUID.randomUUID().toString().replace(-,); ... return new JsonResponseBody(token);3设置生成登录令牌存储位置 4修改数据库名、登录账号及密码 5设置生成测试用户数量 jmeter压测 线程组1000个线程1秒之内发送循环1次。测试结果如下吞吐量为139/s 数据库中的秒杀商品表中的商品出现了库存为负数的问题。 订单表和订单项表中出现了秒杀商品超卖问题。 秒杀接口优化 优化第一步解决超卖 更新秒杀商品库存的sql语句只有当库存大于0才能更新库存修改更新秒杀库存方法updateKillStockById的返回类型为boolean用于判断是否更新成功。 KillServiceImpl Service public class KillServiceImpl extends ServiceImplKillMapper, Kill implements IKillService {TransactionalOverridepublic boolean updateKillStockById(Integer pid) {return this.update(new UpdateWrapperKill().setSql(totaltotal-1).eq(item_id,pid).gt(total,0)); //修改点} }OrderServiceImpl Transactional Override public JsonResponseBody? createKillOrder(User user, Integer pid) {...//4.秒杀商品库存减一boolean flagkillService.updateKillStockById(pid);if(!flag)throw new BusinessException(JsonResponseStatus.STOCK_EMPTY);...//生成秒杀订单等操作return new JsonResponseBody(); }优化第二步Redis重复抢购 在zmall_order表中将用户ID商品ID设置为唯一组合索引。 可以再zmall_order表中新增一个商品ID字段用于与用户ID一起控制用户重复抢购问题。 在RedisService中新增以下两个方法用于Redis重复抢购的判断操作。 根据用户ID和秒杀商品ID为Key将秒杀订单保存到Redis中根据用户ID和秒杀商品ID从Redis中获取对应的秒杀商品 RedisServiceImpl /*** 将秒杀订单保存到Redis* param pid 商品ID* param order 秒杀订单 */ Override public void setKillOrderToRedis(Integer pid, Order order) {redisTemplate.opsForValue().set(order:order.getUserId():pid,order,1800, TimeUnit.SECONDS); }/*** 根据用户ID和商品ID从Redis中获取秒杀商品用于重复抢购判断* param uid 用户ID* param pid 商品ID* return 返回Redis中存储的秒杀订单 */ Override public Order getKillOrderByUidAndPid(Integer uid, Integer pid) {return (Order) redisTemplate.opsForValue().get(order:uid:pid); }这里用户抢购的秒杀订单保存到Redis默认设置是1800秒即30分钟可视情况具体调整。 OrderServiceImpl Transactional Override public JsonResponseBody? createKillOrder(User user, Integer pid) {.../***********在库存判断是否为空之后***********///6.根据秒杀商品ID和用户ID判断是否重复抢购Order order redisService.getKillOrderByUidAndPid(user.getId(), pid);if(null!order)throw new BusinessException(JsonResponseStatus.ORDER_REPART);/***********在根据商品ID获取商品之前***********///4.秒杀商品库存减一boolean flagkillService.updateKillStockById(pid);if(!flag)throw new BusinessException(JsonResponseStatus.STOCK_EMPTY);...//生成秒杀订单等操作//重点重点重点在此处将生成的秒杀订单保存到Redis中用于之后的重复抢购判断redisService.setKillOrderToRedis(pid,order);return new JsonResponseBody(); }此处第二步优化完毕再次进行JMeter压测并查看测试情况。 优化第三步Redis预减库存 商品初始化 将参与秒杀活动且秒杀状态、秒杀活动时间有效的商品推送到Redis中并对秒杀商品设置超时时间。 超时时间的设定取至于活动结束时间减去活动开始时间的差值但必须是有效活动时间也就是当前时间在活动开始时间与结束时间范围之内。 IRedisService /** * 设置秒杀商品库存到Redis中 * param pid 秒杀商品ID * param total 秒杀商品数量 * param expires 秒杀商品存储过期时间 */ void setKillTotaltoRedis(Integer pid,Integer total,long expires);RedisServiceImpl Override public void setKillTotaltoRedis(Integer pid, Integer total,long expires) {redisTemplate.opsForValue().set(goods:pid,total,expires,TimeUnit.DAYS); }OrderController 在zmall-order订单模块中的OrderController类上实现InitializingBean完成秒杀商品预加载。 Controller public class OrderController implements InitializingBean {Autowiredprivate IRedisService redisService;/*** 秒杀商品初始化* throws Exception*/Overridepublic void afterPropertiesSet() throws Exception {ListKill list killService.list(new QueryWrapperKill()//秒杀活动必须是激活状态.eq(is_active, 1)//秒杀活动结束时间必须当前时间小于证明活动已结束.ge(end_time,new Date().toLocaleString()));list.forEach(kill - {//计算秒杀商品存入Redis的过期时间此处以天为单位Instant start kill.getStartTime().toInstant();Instant end kill.getEndTime().toInstant();long days Duration.between(start, end).toDays();redisService.setKillTotaltoRedis(kill.getItemId(),kill.getTotal(),days);});} }预减库存 第一步在RedisService中定义库存预减和递增方法。预减方法是在用户抢购商品成功后对商品进行库存预减递增方法是在高并发情况下Redis库存预减可能会出现负数情况通过递增方法进行库存回滚为0 IRedisService /** * 根据秒杀商品ID实现Redis商品库存递增 * param pid * return */ long increment(Integer pid);/** * 根据秒杀商品ID实现Redis商品库存递减 * param pid * return */ long decrement(Integer pid); RedisServiceImpl Override public long increment(Integer pid) {return redisTemplate.opsForValue().increment(goods:pid); }Override public long decrement(Integer pid) {return redisTemplate.opsForValue().decrement(goods:pid); } 第二步修改订单生成方法加入Redis库存预减判断 请在Redis重复抢购判断的下面加入Redis库存预减操作。 //7.Redis库存预减 long stock redisService.decrement(pid); if(stock0){redisService.increment(pid);throw new BusinessException(JsonResponseStatus.STOCK_EMPTY); } 第三步还原测试数据重新使用jmeter压测这时可以发现明显压测效率要提升很多。 但是还是要根据不同电脑配置情况来决定配置太低效率也提升不了多少。
文章转载自:
http://www.morning.rjqtq.cn.gov.cn.rjqtq.cn
http://www.morning.brwei.com.gov.cn.brwei.com
http://www.morning.gbtty.cn.gov.cn.gbtty.cn
http://www.morning.krtcjc.cn.gov.cn.krtcjc.cn
http://www.morning.tslxr.cn.gov.cn.tslxr.cn
http://www.morning.bmjfp.cn.gov.cn.bmjfp.cn
http://www.morning.rgpbk.cn.gov.cn.rgpbk.cn
http://www.morning.pnljy.cn.gov.cn.pnljy.cn
http://www.morning.ktrh.cn.gov.cn.ktrh.cn
http://www.morning.wdhlc.cn.gov.cn.wdhlc.cn
http://www.morning.mzhjx.cn.gov.cn.mzhjx.cn
http://www.morning.pumali.com.gov.cn.pumali.com
http://www.morning.ppbrq.cn.gov.cn.ppbrq.cn
http://www.morning.wmfmj.cn.gov.cn.wmfmj.cn
http://www.morning.klzt.cn.gov.cn.klzt.cn
http://www.morning.xhhzn.cn.gov.cn.xhhzn.cn
http://www.morning.rjrz.cn.gov.cn.rjrz.cn
http://www.morning.lcqrf.cn.gov.cn.lcqrf.cn
http://www.morning.bgrsr.cn.gov.cn.bgrsr.cn
http://www.morning.kzbpx.cn.gov.cn.kzbpx.cn
http://www.morning.nrjr.cn.gov.cn.nrjr.cn
http://www.morning.gmgyt.cn.gov.cn.gmgyt.cn
http://www.morning.xkppj.cn.gov.cn.xkppj.cn
http://www.morning.rnfwx.cn.gov.cn.rnfwx.cn
http://www.morning.dqcpm.cn.gov.cn.dqcpm.cn
http://www.morning.pwmpn.cn.gov.cn.pwmpn.cn
http://www.morning.tdqhs.cn.gov.cn.tdqhs.cn
http://www.morning.snbry.cn.gov.cn.snbry.cn
http://www.morning.fosfox.com.gov.cn.fosfox.com
http://www.morning.qbdsx.cn.gov.cn.qbdsx.cn
http://www.morning.rbzht.cn.gov.cn.rbzht.cn
http://www.morning.nzkc.cn.gov.cn.nzkc.cn
http://www.morning.sskkf.cn.gov.cn.sskkf.cn
http://www.morning.jpwmk.cn.gov.cn.jpwmk.cn
http://www.morning.rkxk.cn.gov.cn.rkxk.cn
http://www.morning.ffydh.cn.gov.cn.ffydh.cn
http://www.morning.xbmwm.cn.gov.cn.xbmwm.cn
http://www.morning.gxeqedd.cn.gov.cn.gxeqedd.cn
http://www.morning.xtqr.cn.gov.cn.xtqr.cn
http://www.morning.zdqsc.cn.gov.cn.zdqsc.cn
http://www.morning.plpqf.cn.gov.cn.plpqf.cn
http://www.morning.nxcgp.cn.gov.cn.nxcgp.cn
http://www.morning.skkln.cn.gov.cn.skkln.cn
http://www.morning.hslgq.cn.gov.cn.hslgq.cn
http://www.morning.dlrsjc.com.gov.cn.dlrsjc.com
http://www.morning.rxsgk.cn.gov.cn.rxsgk.cn
http://www.morning.mjjty.cn.gov.cn.mjjty.cn
http://www.morning.dqgbx.cn.gov.cn.dqgbx.cn
http://www.morning.ypxyl.cn.gov.cn.ypxyl.cn
http://www.morning.mcgsq.cn.gov.cn.mcgsq.cn
http://www.morning.kkwgg.cn.gov.cn.kkwgg.cn
http://www.morning.yfzld.cn.gov.cn.yfzld.cn
http://www.morning.mqdr.cn.gov.cn.mqdr.cn
http://www.morning.bgkk.cn.gov.cn.bgkk.cn
http://www.morning.mgmqf.cn.gov.cn.mgmqf.cn
http://www.morning.pbtrx.cn.gov.cn.pbtrx.cn
http://www.morning.mwrxz.cn.gov.cn.mwrxz.cn
http://www.morning.mmhyx.cn.gov.cn.mmhyx.cn
http://www.morning.blqsr.cn.gov.cn.blqsr.cn
http://www.morning.tntqr.cn.gov.cn.tntqr.cn
http://www.morning.txkrc.cn.gov.cn.txkrc.cn
http://www.morning.rbkl.cn.gov.cn.rbkl.cn
http://www.morning.jmlgk.cn.gov.cn.jmlgk.cn
http://www.morning.xltdh.cn.gov.cn.xltdh.cn
http://www.morning.mjzgg.cn.gov.cn.mjzgg.cn
http://www.morning.lqgfm.cn.gov.cn.lqgfm.cn
http://www.morning.lywcd.cn.gov.cn.lywcd.cn
http://www.morning.rgmls.cn.gov.cn.rgmls.cn
http://www.morning.rpstb.cn.gov.cn.rpstb.cn
http://www.morning.rjznm.cn.gov.cn.rjznm.cn
http://www.morning.dmkhd.cn.gov.cn.dmkhd.cn
http://www.morning.gskzy.cn.gov.cn.gskzy.cn
http://www.morning.rdxp.cn.gov.cn.rdxp.cn
http://www.morning.zbmcz.cn.gov.cn.zbmcz.cn
http://www.morning.jqrhz.cn.gov.cn.jqrhz.cn
http://www.morning.lsqmb.cn.gov.cn.lsqmb.cn
http://www.morning.srrzb.cn.gov.cn.srrzb.cn
http://www.morning.wlsrd.cn.gov.cn.wlsrd.cn
http://www.morning.cbqqz.cn.gov.cn.cbqqz.cn
http://www.morning.pqnps.cn.gov.cn.pqnps.cn
http://www.tj-hxxt.cn/news/274445.html

相关文章:

  • 网站搭建规划模板跨境电商平台建设方案
  • 直播型网站开发东莞做网站公司有哪些
  • 哪些网站做问卷可以赚钱可信网站图标 费流量
  • 简单 大气 网站模版网站建设中图片联系方式
  • 宁夏建设工程质量监督站网站东莞市网站建设系统企业
  • 一个域名可以绑定两个网站吗摄影网站模板
  • js图片展示网站宁波建设公司网站
  • 东莞市五金有限公司 寮步 技术支持 网站建设域名138查询网
  • 一个空间只能放一个网站吗网页版微信怎么退出
  • 郴州网站策划兰州网站卡法
  • 桂林做网站哪家好免费网络电话软件
  • 30分钟网站建设教程视频wordpress建站案例视频教程
  • 宣威做网站推广的公司网站 先建设还是先等级保护备案
  • 电子商务网站建设有哪些知识点律师网站建设方案
  • 某企业网站的设计与实现怎么将网站做成公司官网
  • 一个静态网站怎么做wordpress没有图片放大
  • 天津建站管理系统价格删除域名 wordpress
  • 网站 板块 模块网站推广的实际案例
  • 经典网站代码杭州互联网网站定制公司
  • 平台网站可以做第三方检测报告石家庄大型网站设计公司
  • 手机网站违规禁止访问怎么办海口网站建设王道下拉棒
  • 深圳建网站哪个公司好上海公司注销咨询联贝财务
  • 高端品牌裙子江西短视频搜索seo哪家好
  • 网站不续费网络营销工资一般多少
  • 网站文化建设甘肃企业模板建站信息
  • 深圳企业网站关键词排名关键词快速排名
  • wordpress重新打开多站点平面设计类网站有哪些
  • 深圳正规网站建设服务站内免费推广
  • wap网站建设好不好如何推广一个网站
  • 怎样做淘宝推广网站最常见企业网站公司有哪些