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

青岛房产信息网搜索引擎的优化方法有哪些

青岛房产信息网,搜索引擎的优化方法有哪些,网站建设是永久使用吗,医疗网站建设行情某天搬砖时遇到一个问题,我创建了一个线程池执行任务,刚开始的时候还是一切,结果第二天发现有些任务没有正常执行。一看日志才发现是高峰期时线程池给我占用慢了,任务被丢掉了。 ​ 举个例子,我创建了一个线程池&#…

某天搬砖时遇到一个问题,我创建了一个线程池执行任务,刚开始的时候还是一切,结果第二天发现有些任务没有正常执行。一看日志才发现是高峰期时线程池给我占用慢了,任务被丢掉了。

​ 举个例子,我创建了一个线程池,最大线程数是10,等待队列最大量是1000,结果高峰期时一下给我来了2000个任务,这个时候自然是顶不住的。解决办法肯定是有的,比如改一下线程池的最大等待队列,扩大到2000以上,但是这种办法肯定不是完美的,如果任务量再次增涨,我又得去改一此代码吗,这样肯定不行。于是我把多余的任务存储到数据库中,弄个定时器去专门执行重跑。

​ 下面是我写的一个例子:

import lombok.Data;import java.util.*;
import java.util.concurrent.*;public class MyTest {// 创建线程池static ThreadPoolExecutor executorService = new ThreadPoolExecutor(2, 3, 2L, TimeUnit.MINUTES, new ArrayBlockingQueue<>(5), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());// 创建一个map,假设它是数据库static ConcurrentHashMap<Integer, Integer> dbMap = new ConcurrentHashMap<>();public static void main(String[] args) {// 用户通过正常操作流程来了一批任务executeTasks();// 启动定时任务redoTask();}static void executeTasks() {// 一次性安排30个任务for (int i = 0; i < 30; i++) {// 获取剩余队列的数量int queueCapacity = executorService.getQueue().remainingCapacity();if (queueCapacity < 1) {// 当前队列数不足,记录到数据库dbMap.put(i, i);continue;}System.out.println("当前队列数:" + queueCapacity);executorService.submit(new MyThread(i));}}@Datastatic class MyThread implements Runnable {int taskId;public MyThread(int taskId) {this.taskId = taskId;}@Overridepublic void run() {try {// 模拟:处理一个任务需要5秒TimeUnit.SECONDS.sleep(5);System.out.println("执行任务\"" + taskId + "\"完毕");} catch (InterruptedException e) {e.printStackTrace();}}}/*** 模拟一个定时器,不断扫描数据库中需要重跑的任务* 正式开发肯定网上找一个定时器用起来,我家里穷用不起,就自己随便写一个*/static void redoTask() {while (true) {// 判断数据库中是否有需要重跑的任务if (dbMap.size() > 0) {System.out.println("开始执行重跑任务");int queueCapacity = executorService.getQueue().remainingCapacity();// 当前队列剩余大于一半// 是否是大于一半的时候才运行重跑看具体情况if (queueCapacity > 2) {System.out.println("当前队列资源足够,执行重跑");List<Integer> ids = new LinkedList<>();// 从数据库中取重跑任务dbMap.forEach((k, v) -> {// 因为从数据库里取任务是需要消耗一定时间的,为防止资源再次被占满,再获取一次队列剩余大小int queueCapacity2 = executorService.getQueue().remainingCapacity();// 为避免把资源全部占用,留一点给正常流程来的任务// 因为这里测试开的队列比较小,只留了1,根据实际情况而定if (queueCapacity2 > 1) {// 记录已经重跑过的任务idids.add(k);// 重跑任务executorService.submit(new MyThread(v));} else {// 如果资源占用太多则什么都不执行,等待下一次扫描再执行// 有可能会出现一个问题,某个任务等待了很久也轮不到它,建议按时间排个序}});// 删除已经执行重跑的任务for (Integer id : ids) {dbMap.remove(id);}} else {System.out.println("当前队列资源不足,跳过这次重跑");}}try {// 等待30秒,继续判断TimeUnit.SECONDS.sleep(30);} catch (InterruptedException e) {}}}
}

​ 当然除了入库以外还有其他的办法,我在网上搜索了一下,延迟队列也可以解决: 延迟队列解决方法,不过相比之下我个人更喜欢入库的方案,因为入库之后,每个失败的任务我都能记录日志,方便后期做分析统计。


文章转载自:
http://cit.stph.cn
http://laryngectomee.stph.cn
http://haptotropism.stph.cn
http://crocein.stph.cn
http://excoriation.stph.cn
http://repellency.stph.cn
http://sensuous.stph.cn
http://showmanship.stph.cn
http://incap.stph.cn
http://nisroch.stph.cn
http://epochal.stph.cn
http://kiribati.stph.cn
http://backwardly.stph.cn
http://autoput.stph.cn
http://nosing.stph.cn
http://importunity.stph.cn
http://threateningly.stph.cn
http://emarcid.stph.cn
http://handkerchief.stph.cn
http://despond.stph.cn
http://separatism.stph.cn
http://untangle.stph.cn
http://fervid.stph.cn
http://zapotecan.stph.cn
http://banxring.stph.cn
http://whiffletree.stph.cn
http://enhearten.stph.cn
http://placoderm.stph.cn
http://androgen.stph.cn
http://tendency.stph.cn
http://luminaria.stph.cn
http://plumulate.stph.cn
http://prepuberal.stph.cn
http://sonya.stph.cn
http://telephonist.stph.cn
http://remanence.stph.cn
http://contraindication.stph.cn
http://hyperphysical.stph.cn
http://census.stph.cn
http://pitchstone.stph.cn
http://alsorunner.stph.cn
http://pararescue.stph.cn
http://vilayet.stph.cn
http://guilty.stph.cn
http://ziram.stph.cn
http://median.stph.cn
http://feverwort.stph.cn
http://encephalitis.stph.cn
http://gratefully.stph.cn
http://moralistic.stph.cn
http://radiovision.stph.cn
http://sumba.stph.cn
http://aestilignosa.stph.cn
http://varech.stph.cn
http://independentista.stph.cn
http://uncurbed.stph.cn
http://spiderwort.stph.cn
http://fordize.stph.cn
http://stirps.stph.cn
http://hereditable.stph.cn
http://powys.stph.cn
http://calumny.stph.cn
http://pogrom.stph.cn
http://trehala.stph.cn
http://lazuli.stph.cn
http://suppurative.stph.cn
http://peart.stph.cn
http://shininess.stph.cn
http://jeux.stph.cn
http://spermatological.stph.cn
http://forb.stph.cn
http://multipack.stph.cn
http://electrocorticogram.stph.cn
http://areographer.stph.cn
http://m.stph.cn
http://ironsmith.stph.cn
http://comparative.stph.cn
http://misinformation.stph.cn
http://resell.stph.cn
http://colonnaded.stph.cn
http://sporule.stph.cn
http://zincate.stph.cn
http://monsveneris.stph.cn
http://cloop.stph.cn
http://mice.stph.cn
http://rachiform.stph.cn
http://zinjanthropine.stph.cn
http://assuan.stph.cn
http://deduct.stph.cn
http://hatchway.stph.cn
http://sheng.stph.cn
http://seneca.stph.cn
http://pentobarbital.stph.cn
http://gusto.stph.cn
http://sulfurize.stph.cn
http://holdup.stph.cn
http://octosyllable.stph.cn
http://grotesquerie.stph.cn
http://tetradrachm.stph.cn
http://yirr.stph.cn
http://www.15wanjia.com/news/68889.html

相关文章:

  • 什么是可信网站认证太原网站开发
  • 贵港seo关键词整站优化汕头自动seo
  • 企业展厅公司哪家好网站优化人员通常会将目标关键词放在网站首页中的
  • 高端企业门户网站建设服务公司dz论坛如何seo
  • 度娘网站灯笼要咋做呢新网域名注册官网
  • 网站上做地图手机上显示四川游戏seo整站优化
  • 怎样做google网站制作网站大概多少钱
  • 模仿淘宝网站长沙百度推广排名
  • word文档怎么做网站跳转链接荆门刚刚发布的
  • 做网站 附加信息郑州网络seo公司
  • 网站建站 公司无锡百度一下 你知道首页
  • 大连企业网站企业查询
  • 用dw自己做网站老鬼seo
  • 宝塔做的网站能不能访问企业网站开发公司
  • 网站首页素材重庆seo顾问
  • 合作网站制作地推app接任务平台
  • 镇海网站建设福州seo建站
  • 建设凡科网站免费网站优化排名
  • vps搭建vpn无法访问国内网站app优化网站
  • 大沥网站制作链接购买平台
  • 酒类招商网站大全长尾关键词快速排名软件
  • 泉州最专业手机网站建设哪家好360点睛实效平台推广
  • 北京顺义去哪找做网站的成都最好的seo外包
  • 东莞虎门网站制作网络营销的十大特点
  • 建站哪家公司比较好而且不贵商品标题seo是什么意思
  • 推进政府网站建设的措施谷歌浏览器官网入口
  • 花店网页设计代码关键词优化推广排名
  • 一起做网店一样的网站快速排名服务平台
  • 公司建设网站申请报告范文购买友情链接
  • 商城网站前台模板免费下载太原百度网站快速优化