From 1ff73c67f5c46a18da6089027bc95f3adb0e6669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=BB=E6=98=8E?= Date: Sun, 18 Aug 2019 10:04:32 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9A=8F=E6=9C=BA=E6=8F=90=E4=BA=A4=E4=B8=80?= =?UTF-8?q?=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../volatileTest/VolatileTest.java | 47 +++++++------------ .../guava/eventbus/SimpleEventBusExample.java | 17 ++++--- .../eventbus/listener/SimpleListener.java | 30 ++++++------ .../study/guava/string/TestStringOps.java | 18 ++++--- mybatis/mybatis.iml | 1 + mybatis/pom.xml | 5 ++ 6 files changed, 60 insertions(+), 58 deletions(-) diff --git a/concurrent/src/main/java/com/chen/study/concurrent/concurrent2/volatileTest/VolatileTest.java b/concurrent/src/main/java/com/chen/study/concurrent/concurrent2/volatileTest/VolatileTest.java index 6bfe18e..9e1ca27 100644 --- a/concurrent/src/main/java/com/chen/study/concurrent/concurrent2/volatileTest/VolatileTest.java +++ b/concurrent/src/main/java/com/chen/study/concurrent/concurrent2/volatileTest/VolatileTest.java @@ -6,36 +6,23 @@ */ public class VolatileTest { - private static int INIT_VALUE = 0; - private static int MAX_LIMIT = 5; - - public static void main(String[] args) throws InterruptedException { - new Thread(() -> { - int localValue = INIT_VALUE; - while (localValue < MAX_LIMIT){ - if (localValue != INIT_VALUE){ - System.out.printf("数值更新到到[%d]\n", INIT_VALUE); - localValue = INIT_VALUE; - } + /** + * 如果不使用volatile,程序不会停止 + */ + public volatile static boolean stop = false; + + public static void main(String[] args) throws + InterruptedException { + Thread thread = new Thread(() -> { + int i = 0; + while (!stop) { + i++; } - }, "reader").start(); - - - Thread.sleep(100); - - - new Thread(() -> { - int localValue = INIT_VALUE; - while (localValue < MAX_LIMIT){ - INIT_VALUE = ++localValue; - System.out.printf("更新数值到[%d]\n", INIT_VALUE); - try { - Thread.sleep(500); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - }, "updater").start(); - + }); + thread.start(); + System.out.println("begin start thread"); + Thread.sleep(1000); + stop = true; + thread.join(); } } diff --git a/guava/src/main/java/com/chen/study/guava/eventbus/SimpleEventBusExample.java b/guava/src/main/java/com/chen/study/guava/eventbus/SimpleEventBusExample.java index 56f5d5f..0fb0049 100644 --- a/guava/src/main/java/com/chen/study/guava/eventbus/SimpleEventBusExample.java +++ b/guava/src/main/java/com/chen/study/guava/eventbus/SimpleEventBusExample.java @@ -50,17 +50,20 @@ public void test2() { eventBus.register(new SimpleListener()); // 发送一个事件 - System.out.println(Thread.currentThread().getName() + "发送第一个"); +// System.out.println(Thread.currentThread().getName() + "发送第一个"); eventBus.post("我来了"); - System.out.println(Thread.currentThread().getName() + "发送第二个"); - eventBus.post("我来了"); - System.out.println(Thread.currentThread().getName() + "发送第三个"); - eventBus.post("我来了"); + System.out.println("执行完成啊啊啊啊"); - System.out.println(Thread.currentThread().getName() + "发送第四个"); - eventBus.post("我来了"); +// System.out.println(Thread.currentThread().getName() + "发送第二个"); +// eventBus.post("我来了"); +// +// System.out.println(Thread.currentThread().getName() + "发送第三个"); +// eventBus.post("我来了"); +// +// System.out.println(Thread.currentThread().getName() + "发送第四个"); +// eventBus.post("我来了"); diff --git a/guava/src/main/java/com/chen/study/guava/eventbus/listener/SimpleListener.java b/guava/src/main/java/com/chen/study/guava/eventbus/listener/SimpleListener.java index 4d046e6..54cb6ef 100644 --- a/guava/src/main/java/com/chen/study/guava/eventbus/listener/SimpleListener.java +++ b/guava/src/main/java/com/chen/study/guava/eventbus/listener/SimpleListener.java @@ -1,6 +1,5 @@ package com.chen.study.guava.eventbus.listener; -import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.Subscribe; /** @@ -17,28 +16,29 @@ public class SimpleListener { * @param event */ @Subscribe - @AllowConcurrentEvents +// @AllowConcurrentEvents public void doAction(String event){ - System.out.println("处理器1:" + event); - try { - Thread.sleep(2_000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - System.out.println(Thread.currentThread().getName() + "处理其1 完成"); + throw new RuntimeException("异常来了吗啊"); +// System.out.println("处理器1:" + event); +// try { +// Thread.sleep(2_000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// System.out.println(Thread.currentThread().getName() + "处理其1 完成"); } @Subscribe - @AllowConcurrentEvents +// @AllowConcurrentEvents public void doAction2(String event){ System.out.println("处理器2:" + event); - try { - Thread.sleep(10_000); - } catch (InterruptedException e) { - e.printStackTrace(); - } +// try { +// Thread.sleep(10_000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } System.out.println(Thread.currentThread().getName() + "处理2完成"); } diff --git a/guava/src/main/java/com/chen/study/guava/string/TestStringOps.java b/guava/src/main/java/com/chen/study/guava/string/TestStringOps.java index 452f784..fa0db0b 100755 --- a/guava/src/main/java/com/chen/study/guava/string/TestStringOps.java +++ b/guava/src/main/java/com/chen/study/guava/string/TestStringOps.java @@ -53,11 +53,12 @@ public void testJoiner() throws IOException { // 连接的内容置入到stringBuffer - StringBuffer stringBuffer = new StringBuffer(); - StringBuffer buffer = Joiner.on(",") + StringBuffer stringBuffer = new StringBuffer().append("max("); + Joiner.on(",") .skipNulls() .appendTo(stringBuffer, list); - System.out.println(buffer); + stringBuffer.append(")"); + System.out.println(stringBuffer); } @@ -104,6 +105,14 @@ public void testSplitter() { .split("a-100,b-200"); System.out.println(map); + + + // 拆分成一个map + Map map2 = Splitter.onPattern("&") + .withKeyValueSeparator("=") + .split("a=1&b=2&c=3&d="); + System.out.println(map2); + } /** @@ -149,7 +158,6 @@ public void testCaseFormat() { /** * 我用下面的方式转 */ - // 字符串转成驼峰 isTest String is_emp_test = Strman.toCamelCase("IS_test".toLowerCase()); System.out.println(is_emp_test); @@ -166,8 +174,6 @@ public void testCaseFormat() { String studlyCase = Strman.toStudlyCase("is_test"); System.out.println(studlyCase); - - } } diff --git a/mybatis/mybatis.iml b/mybatis/mybatis.iml index 05144be..1b95b74 100644 --- a/mybatis/mybatis.iml +++ b/mybatis/mybatis.iml @@ -25,6 +25,7 @@ + diff --git a/mybatis/pom.xml b/mybatis/pom.xml index 12288f3..a77c51f 100644 --- a/mybatis/pom.xml +++ b/mybatis/pom.xml @@ -72,6 +72,11 @@ 1.1.14 + + org.mybatis + mybatis-spring + 2.0.0 +