1. ThreadPoolUtils import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUn ...
分类:
编程语言 时间:
2020-01-06 14:46:30
阅读次数:
85
在多线程领域:所谓阻塞,在某些情况下会挂起线程(即阻塞),一旦条件满足,被挂起的线程又会自动被唤醒 为什么需要BlockingQueue 好处是我们不需要关心什么时候需要阻塞线程,什么时候需要唤醒线程,因为这一切BlockingQueue都给你一手操办了,在concurrent包发布以前,在多线程环 ...
分类:
其他好文 时间:
2020-01-05 13:35:29
阅读次数:
81
本地电脑使用客户端,阿里云服务器使用远程桌面用服务器端 测试代码如下(代码来源于网络,已测试通过): 客户端: 1 import java.net.*; 2 import java.io.*; 3 import java.util.concurrent.ExecutionException; 4 5 ...
分类:
编程语言 时间:
2020-01-04 16:38:22
阅读次数:
190
```python import requests import re import uuid from concurrent.futures import ThreadPoolExecutor pool = ThreadPoolExecutor(50) # 爬虫三部曲 # 1.发送请求 def g... ...
分类:
其他好文 时间:
2020-01-02 20:58:12
阅读次数:
111
1.线程池 import time from concurrent.futures import ThreadPoolExecutor def func(n): time.sleep(2) print(n) t_pool = ThreadPoolExecutor(max_workers=5) # 创 ...
分类:
编程语言 时间:
2020-01-02 20:35:31
阅读次数:
91
https://en.wikipedia.org/wiki/Aspect-oriented_programming Action Agent-oriented Array-oriented Automata-based Concurrent computing Relativistic progra ...
分类:
其他好文 时间:
2020-01-01 16:57:08
阅读次数:
86
众所周知,i++分为三步: 1. 读取i的值 2. 计算i+1 3. 将计算出i+1赋给i 可以使用锁来保持操作的原子性,用volatile保持值的可见性和操作顺序性; 如果仅仅是计算操作,我们自然就想到了java.util.concurrent.atomic包下的原子类,则不必考虑锁的升级、获取、 ...
分类:
其他好文 时间:
2020-01-01 16:28:19
阅读次数:
161
package com.example.demo.utils;import java.lang.reflect.Field;import java.util.concurrent.*;public class Test1 { static ThreadLocal threadLocal = new ...
分类:
编程语言 时间:
2019-12-29 11:07:00
阅读次数:
116
CAS CAS:Compare and Swap, 翻译成比较并交换。 java.util.concurrent包中借助CAS实现了区别于synchronized同步锁的一种乐观锁。 其原理是CAS有3个操作数,内存值V,旧的预期值A,要修改的新值B。当且仅当预期值A和内存值V相同时,将内存值V修改 ...
分类:
其他好文 时间:
2019-12-28 20:40:42
阅读次数:
91
1、简述synchroized和java.util.concurrent.locks.Lock的异同? 1.synchronized 用在方法和代码块的区别? a. 可以只对需要同步的使用 b.与wait(),notify()和notifyall()方法使用比较方便 2.wait() a。释放持有的 ...
分类:
其他好文 时间:
2019-12-28 14:38:49
阅读次数:
89