![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
java多线程
蓝色KK
职场菜鸟。
展开
-
java多线程基础:volatile关键词与可见性
public class TestVolatile { public static void main(String[] args) { ThreadA threadA = new ThreadA(); new Thread(threadA).start(); while (true){ if (thread...原创 2018-05-05 11:24:22 · 186 阅读 · 0 评论 -
java多线程基础:原子变量
使用了volatile就一定线程安全吗?public class TestAtomic { public static void main(String[] args) { ThreadB threadB = new ThreadB(); for (int i = 0; i < 10; i++) { new Thread(thr...原创 2018-05-05 12:27:10 · 380 阅读 · 0 评论 -
java多线程基础:Callable
创建线程除了Thread Runnable 还有Callablepublic class TestCallable { public static void main(String[] args) { ThreadD threadD = new ThreadD(); FutureTask<Long> futureTask = new Future...原创 2018-05-05 19:51:54 · 393 阅读 · 0 评论 -
java多线程基础:读写锁
读写锁的特点,读读不互斥,读写,写写互斥。private ReadWriteLock lock = new ReentrantReadWriteLock();lock.readLock().lock(); //开启读锁lock.readLock().unlock();//释放读锁 lock.writeLock().lock();//开启写锁lock.writeLock().unlock();//释...原创 2018-05-06 22:29:10 · 201 阅读 · 0 评论 -
java多线程基础:线程的状态
打开jdk源码,在Thread类中找到State枚举类。 /** * A thread state. A thread can be in one of the following states: * <ul> * <li>{@link #NEW}<br> * A thread that has not yet ...原创 2018-05-13 22:05:05 · 196 阅读 · 0 评论 -
java多线程基础:多线程的多种创建方式
1继承Threadpublic class TestThreadCreate extends Thread{ @Override public void run() { super.run(); }}2实现Runnable接口public class TestThreadCreate implements Runnable{ @Override ...原创 2018-05-13 22:29:36 · 191 阅读 · 0 评论