Skip to content

Commit

Permalink
随机提交一次
Browse files Browse the repository at this point in the history
  • Loading branch information
chentianming11 committed Aug 18, 2019
1 parent 382d216 commit 1ff73c6
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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("我来了");



Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.chen.study.guava.eventbus.listener;

import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;

/**
Expand All @@ -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完成");

}
Expand Down
18 changes: 12 additions & 6 deletions guava/src/main/java/com/chen/study/guava/string/TestStringOps.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand Down Expand Up @@ -104,6 +105,14 @@ public void testSplitter() {
.split("a-100,b-200");
System.out.println(map);



// 拆分成一个map
Map<String, String> map2 = Splitter.onPattern("&")
.withKeyValueSeparator("=")
.split("a=1&b=2&c=3&d=");
System.out.println(map2);

}

/**
Expand Down Expand Up @@ -149,7 +158,6 @@ public void testCaseFormat() {
/**
* 我用下面的方式转
*/

// 字符串转成驼峰 isTest
String is_emp_test = Strman.toCamelCase("IS_test".toLowerCase());
System.out.println(is_emp_test);
Expand All @@ -166,8 +174,6 @@ public void testCaseFormat() {
String studlyCase = Strman.toStudlyCase("is_test");
System.out.println(studlyCase);



}

}
1 change: 1 addition & 0 deletions mybatis/mybatis.iml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: org.mybatis.generator:mybatis-generator-core:1.3.5" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:druid:1.1.14" level="project" />
<orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:2.0.0" level="project" />
<orderEntry type="module" module-name="util" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.4" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:23.6-jre" level="project" />
Expand Down
5 changes: 5 additions & 0 deletions mybatis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
<version>1.1.14</version>
</dependency>

<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.0</version>
</dependency>


<dependency>
Expand Down

0 comments on commit 1ff73c6

Please sign in to comment.