提交 d475acb3 编写于 作者: 武汉红喜's avatar 武汉红喜

author

上级 634815d9
package org.hongxi.java.util.concurrent;
import java.util.concurrent.atomic.AtomicLong;
/**
* @author shenhongxi 2019/09/01
*/
public class AtomicTest {
private static AtomicLong count = new AtomicLong();
private static Integer[] arrayOne = new Integer[] {0, 1, 2, 3, 0, 5, 6, 0, 56, 0};
private static Integer[] arrayTwo = new Integer[] {10, 1, 2, 3, 0, 5, 6, 0, 56, 0};
public static void main(String[] args) throws InterruptedException {
Thread threadOne = new Thread(() -> {
int size = arrayOne.length;
for (int i = 0; i < size; i++) {
if (arrayOne[i].intValue() == 0)
count.incrementAndGet();
}
});
Thread threadTwo = new Thread(() -> {
int size = arrayTwo.length;
for (int i = 0; i < size; i++) {
if (arrayTwo[i].intValue() == 0)
count.incrementAndGet();
}
});
threadOne.start();
threadTwo.start();
// 等待线程执行完毕
threadOne.join();
threadTwo.join();
System.out.println("count 0:" + count.get());
}
}
package org.hongxi.java.util.concurrent;
/**
* Created by shenhongxi on 2019-08-31.
* @author shenhongxi 2019-08-31.
*/
public class DaemonThreadTest {
......
package org.hongxi.java.util.concurrent;
/**
* Created by shenhongxi on 2019-08-31.
* @author shenhongxi 2019-08-31.
*/
public class DeadLockTest2 {
......
package org.hongxi.java.util.concurrent;
import java.util.concurrent.ThreadLocalRandom;
/**
* @author shenhongxi 2019-09-01
*/
public class ThreadLocalRandomTest {
public static void main(String[] args) {
ThreadLocalRandom random = ThreadLocalRandom.current();
for (int i = 0; i < 10; i++) {
System.out.println(random.nextInt(5));
}
}
}
package org.hongxi.java.util.concurrent;
/**
* Created by shenhongxi on 2019-08-31.
* @author shenhongxi 2019-08-31.
*/
public class ThreadLocalTest {
......
......@@ -3,7 +3,7 @@ package org.hongxi.whatsmars.kafka;
import kafka.Kafka;
/**
* Created by shenhongxi on 2019-08-27.
* @author shenhongxi 2019-08-27.
*/
public class KafkaStartup {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册