From fbaeea42a64f80cb329eeb2deeb53a44ccb7d1cf Mon Sep 17 00:00:00 2001 From: darkday9 Date: Fri, 28 Aug 2020 20:56:54 +0800 Subject: [PATCH 1/7] =?UTF-8?q?1=E3=80=81=E6=94=B9=E7=94=A8ExecutorService?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E7=AB=A0=E8=AE=B0=E5=BD=95=E7=9A=84?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=EF=BC=8C=E4=B9=8B=E5=89=8D=E7=9A=84TaskRunne?= =?UTF-8?q?r=E9=98=BB=E5=A1=9E=E4=BA=86main=E7=BA=BF=E7=A8=8B=E5=A6=82?= =?UTF-8?q?=E6=9E=9C=E5=8A=A0=E5=85=A5=E6=96=B0=E7=9A=84CommandRunner?= =?UTF-8?q?=E5=88=99=E4=B8=8D=E4=BC=9A=E5=BE=97=E5=88=B0=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=202=E3=80=81=E6=96=87=E7=AB=A0=E8=AE=B0=E5=BD=95=E7=9A=84save?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=B9=8B=E5=89=8D=E7=94=A8=E4=BA=86bufferLis?= =?UTF-8?q?t=E4=BD=86=E5=85=B6=E5=AE=9E=E6=B2=A1=E4=BB=80=E4=B9=88?= =?UTF-8?q?=E4=BD=9C=E7=94=A8=E5=9B=A0=E6=AD=A4=E4=B9=9F=E5=81=9A=E4=BA=86?= =?UTF-8?q?=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blog/core/schedule/ArticleLookTask.java | 46 +++++++------------ .../java/com/zyd/blog/runner/TaskRunner.java | 25 ---------- 2 files changed, 17 insertions(+), 54 deletions(-) delete mode 100644 blog-web/src/main/java/com/zyd/blog/runner/TaskRunner.java diff --git a/blog-web/src/main/java/com/zyd/blog/core/schedule/ArticleLookTask.java b/blog-web/src/main/java/com/zyd/blog/core/schedule/ArticleLookTask.java index 67b8b8a..7d38ece 100644 --- a/blog-web/src/main/java/com/zyd/blog/core/schedule/ArticleLookTask.java +++ b/blog-web/src/main/java/com/zyd/blog/core/schedule/ArticleLookTask.java @@ -1,5 +1,6 @@ package com.zyd.blog.core.schedule; +import cn.hutool.core.thread.ThreadFactoryBuilder; import com.zyd.blog.business.entity.ArticleLook; import com.zyd.blog.business.service.BizArticleLookService; import com.zyd.blog.business.service.BizArticleService; @@ -7,10 +8,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; +import java.util.concurrent.*; /** * @author yadong.zhang (yadong.zhang0415(a)gmail.com) @@ -23,12 +21,20 @@ import java.util.concurrent.BlockingQueue; @Component @RequiredArgsConstructor public class ArticleLookTask { + ExecutorService executorService = createExecutor(); private final BizArticleService bizArticleService; private final BizArticleLookService articleLookService; - private BlockingQueue queue = new ArrayBlockingQueue<>(1024); + private static ExecutorService createExecutor() { + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder(). + setNamePrefix("article-look").setDaemon(true).build(); + + return new ThreadPoolExecutor(1, 2, 10L, TimeUnit.SECONDS, + new LinkedBlockingQueue<>(1024), namedThreadFactory, + new ThreadPoolExecutor.AbortPolicy()); + } /** * 保存文章的浏览记录,先进先出 @@ -37,33 +43,15 @@ public class ArticleLookTask { if (null == articleLook) { return; } - queue.offer(articleLook); + executorService.submit(() -> save(articleLook)); } - public void save() { - List bufferList = new ArrayList<>(); - while (true) { - try { - bufferList.add(queue.take()); - for (ArticleLook articleLook : bufferList) { - if (!bizArticleService.isExist(articleLook.getArticleId())) { - log.warn("{}-该文章不存在!", articleLook.getArticleId()); - continue; - } - articleLookService.insert(articleLook); - } - } catch (InterruptedException e) { - log.error("保存文章浏览记录失败--->[{}]", e.getMessage()); - // 防止缓冲队列填充数据出现异常时不断刷屏 - try { - Thread.sleep(1000); - } catch (Exception err) { - log.error(err.getMessage()); - } - } finally { - bufferList.clear(); - } + private void save(ArticleLook articleLook) { + if (!bizArticleService.isExist(articleLook.getArticleId())) { + log.warn("{}-该文章不存在!", articleLook.getArticleId()); + return; } + articleLookService.insert(articleLook); } } diff --git a/blog-web/src/main/java/com/zyd/blog/runner/TaskRunner.java b/blog-web/src/main/java/com/zyd/blog/runner/TaskRunner.java deleted file mode 100644 index eb5baa7..0000000 --- a/blog-web/src/main/java/com/zyd/blog/runner/TaskRunner.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.zyd.blog.runner; - -import com.zyd.blog.core.schedule.ArticleLookTask; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.stereotype.Component; - -/** - * 执行保存文章浏览记录任务 - * - * @author kongchong - * date: 2019-07-10 11:17 - */ -@Component -public class TaskRunner implements ApplicationRunner { - - @Autowired - private ArticleLookTask articleLookTask; - - @Override - public void run(ApplicationArguments args) { - articleLookTask.save(); - } -} -- Gitee From 75c21d98be3f3ac0797fac8a01b5509dc736dcc3 Mon Sep 17 00:00:00 2001 From: darkday9 Date: Fri, 28 Aug 2020 21:11:14 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E8=B0=83=E6=95=B4ArticleLookTask=E7=9A=84e?= =?UTF-8?q?xecutor=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/zyd/blog/core/schedule/ArticleLookTask.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/blog-web/src/main/java/com/zyd/blog/core/schedule/ArticleLookTask.java b/blog-web/src/main/java/com/zyd/blog/core/schedule/ArticleLookTask.java index 7d38ece..dbbfa71 100644 --- a/blog-web/src/main/java/com/zyd/blog/core/schedule/ArticleLookTask.java +++ b/blog-web/src/main/java/com/zyd/blog/core/schedule/ArticleLookTask.java @@ -31,9 +31,11 @@ public class ArticleLookTask { ThreadFactory namedThreadFactory = new ThreadFactoryBuilder(). setNamePrefix("article-look").setDaemon(true).build(); - return new ThreadPoolExecutor(1, 2, 10L, TimeUnit.SECONDS, + ThreadPoolExecutor executor= new ThreadPoolExecutor(1, 2, 100L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(1024), namedThreadFactory, - new ThreadPoolExecutor.AbortPolicy()); + new ThreadPoolExecutor.DiscardPolicy()); + executor.allowCoreThreadTimeOut(true); + return executor; } /** -- Gitee From 0592943e1b300ec07bf14ab8c5843c7854c48912 Mon Sep 17 00:00:00 2001 From: darkday9 Date: Fri, 28 Aug 2020 21:28:50 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/zyd/blog/core/schedule/ArticleLookTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blog-web/src/main/java/com/zyd/blog/core/schedule/ArticleLookTask.java b/blog-web/src/main/java/com/zyd/blog/core/schedule/ArticleLookTask.java index dbbfa71..ea2ef06 100644 --- a/blog-web/src/main/java/com/zyd/blog/core/schedule/ArticleLookTask.java +++ b/blog-web/src/main/java/com/zyd/blog/core/schedule/ArticleLookTask.java @@ -31,7 +31,7 @@ public class ArticleLookTask { ThreadFactory namedThreadFactory = new ThreadFactoryBuilder(). setNamePrefix("article-look").setDaemon(true).build(); - ThreadPoolExecutor executor= new ThreadPoolExecutor(1, 2, 100L, TimeUnit.SECONDS, + ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 2, 100L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.DiscardPolicy()); executor.allowCoreThreadTimeOut(true); -- Gitee From 5163e94666bf39c59d58c4aeae9d5156665f7dcb Mon Sep 17 00:00:00 2001 From: darkday9 Date: Sun, 30 Aug 2020 21:15:41 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E5=8F=8A=E7=AE=A1=E7=90=86=E5=91=98=E5=A4=B4?= =?UTF-8?q?=E5=83=8F=E3=80=81=E2=80=9CMOdal=E2=80=9D=E6=8B=BC=E5=86=99?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../static/assets/js/gentelella.core.js | 7 -- .../main/resources/templates/article/tags.ftl | 4 +- .../resources/templates/article/types.ftl | 4 +- .../main/resources/templates/file/list.ftl | 4 +- .../resources/templates/include/macros.ftl | 92 +------------------ .../src/main/resources/templates/index.ftl | 2 - .../resources/templates/layout/setting.ftl | 2 +- .../main/resources/templates/link/list.ftl | 4 +- .../main/resources/templates/notice/list.ftl | 4 +- .../resources/templates/resources/list.ftl | 4 +- .../main/resources/templates/role/list.ftl | 4 +- .../resources/templates/template/list.ftl | 4 +- .../main/resources/templates/update/list.ftl | 4 +- .../main/resources/templates/user/list.ftl | 4 +- 14 files changed, 22 insertions(+), 121 deletions(-) diff --git a/blog-admin/src/main/resources/static/assets/js/gentelella.core.js b/blog-admin/src/main/resources/static/assets/js/gentelella.core.js index e29db05..5f0ca5f 100644 --- a/blog-admin/src/main/resources/static/assets/js/gentelella.core.js +++ b/blog-admin/src/main/resources/static/assets/js/gentelella.core.js @@ -51,12 +51,6 @@ var gentelella = window.gentelella || { return validator.checkAll($(this)) || (b = !1), b && this.submit(), !1 })); }, - initHelloMsg: function () { - var $helloMsg = $("#hello_msg"); - var now = new Date(); - var nowHours = now.getHours(); - $helloMsg.html((nowHours >= 0 && nowHours <= 5) ? "凌晨好" : (nowHours > 5 && nowHours <= 9) ? "早上好" : ((nowHours > 9 && nowHours <= 12) ? "上午好" : ((nowHours > 12 && nowHours <= 13) ? "中午好" : ((nowHours > 13 && nowHours <= 18) ? "下午好" : "晚上好")))); - }, initSwitchery: function (delay) { setTimeout(function () { var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch')); @@ -166,5 +160,4 @@ $(document).ready(function () { gentelella.initSidebar(); gentelella.initDaterangepicker(); gentelella.initValidator(); - gentelella.initHelloMsg(); }); \ No newline at end of file diff --git a/blog-admin/src/main/resources/templates/article/tags.ftl b/blog-admin/src/main/resources/templates/article/tags.ftl index dd075e0..c822138 100644 --- a/blog-admin/src/main/resources/templates/article/tags.ftl +++ b/blog-admin/src/main/resources/templates/article/tags.ftl @@ -33,7 +33,7 @@ -<@addOrUpdateMOdal defaultTitle="添加标签"> +<@addOrUpdateModal defaultTitle="添加标签">
@@ -47,7 +47,7 @@
- + <@footer> - \ No newline at end of file diff --git a/blog-web/src/main/resources/templates/archives.ftl b/blog-web/src/main/resources/templates/archives.ftl index ca3863c..a767a66 100644 --- a/blog-web/src/main/resources/templates/archives.ftl +++ b/blog-web/src/main/resources/templates/archives.ftl @@ -79,6 +79,5 @@ })(); }); - \ No newline at end of file diff --git a/blog-web/src/main/resources/templates/article.ftl b/blog-web/src/main/resources/templates/article.ftl index 6780504..653ec40 100644 --- a/blog-web/src/main/resources/templates/article.ftl +++ b/blog-web/src/main/resources/templates/article.ftl @@ -216,7 +216,6 @@ var coverImg = $("#cover-img").attr("src") || "${config.staticWebSite}/img/default_article_cover.jpg"; window._bd_share_config={"common":{"bdSnsKey":{},"bdText":bdText,"bdMini":"2","bdMiniList":["mshare","qzone","tsina","bdysc","weixin","renren","tqq","kaixin001","tqf","tieba","douban","bdhome","sqq","youdao","sdo","qingbiji","mail","isohu","ty","fbook","twi","linkedin","h163","evernotecn","copy","print"],"bdPic":coverImg,"bdStyle":"1","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)]; - diff --git a/blog-web/src/main/resources/templates/disclaimer.ftl b/blog-web/src/main/resources/templates/disclaimer.ftl index b413a2c..77abaac 100644 --- a/blog-web/src/main/resources/templates/disclaimer.ftl +++ b/blog-web/src/main/resources/templates/disclaimer.ftl @@ -39,7 +39,4 @@ <#include "layout/sidebar.ftl"/> -<@footer> - - \ No newline at end of file diff --git a/blog-web/src/main/resources/templates/guestbook.ftl b/blog-web/src/main/resources/templates/guestbook.ftl index 02837fb..6f931b6 100644 --- a/blog-web/src/main/resources/templates/guestbook.ftl +++ b/blog-web/src/main/resources/templates/guestbook.ftl @@ -36,8 +36,6 @@ <@footer> - - diff --git a/blog-web/src/main/resources/templates/index.ftl b/blog-web/src/main/resources/templates/index.ftl index 482c1b3..d7e8e3a 100644 --- a/blog-web/src/main/resources/templates/index.ftl +++ b/blog-web/src/main/resources/templates/index.ftl @@ -9,22 +9,6 @@
<@prompt>
@@ -101,17 +85,16 @@
-
亲,啥也没找到啊~~[囧]
-
换个姿势,再来一次~~
+
暂无相关文章
- 惩罚我 +
- + diff --git a/blog-web/src/main/resources/templates/layout/sidebar.ftl b/blog-web/src/main/resources/templates/layout/sidebar.ftl index 72130e8..fcc4483 100644 --- a/blog-web/src/main/resources/templates/layout/sidebar.ftl +++ b/blog-web/src/main/resources/templates/layout/sidebar.ftl @@ -1,11 +1,5 @@
<#if articleDetail??> - <#else>