摘要: JSONP实现跨域 1.AJAX跨域访问 2.后端 阅读全文
posted @ 2019-10-22 22:19 我爱si搬砖 阅读(166) 评论(0) 推荐(0) 编辑
摘要: /** * Future 未来的执行结果 */ public class T06_Future { public static void main(String[] args) throws ExecutionException, InterruptedException { // 未来任务, 既是Runnable 也是 Future FutureTask<Integer> task = new 阅读全文
posted @ 2019-10-22 15:44 我爱si搬砖 阅读(143) 评论(0) 推荐(0) 编辑
摘要: /** * ParallelStreamAPI * */ public class T14_ParallelStreamAPI { public static void main(String[] args) { List nums = new ArrayList(); Random random = new Random(); ... 阅读全文
posted @ 2019-10-22 15:16 我爱si搬砖 阅读(142) 评论(0) 推荐(0) 编辑
摘要: /** * T12_ForkJoinPool 分而治之 * Fork: 分叉 * Join: 合并 * * 将一个任务拆分多个任务执行(可以无限切分),然后将结果合并 * * 比如大量的并行计算, 如下: 求100_0000个数字之和, 使用多线程 */ public class T12_ForkJoinPool { static int[] nums = n... 阅读全文
posted @ 2019-10-22 14:53 我爱si搬砖 阅读(167) 评论(0) 推荐(0) 编辑
摘要: /** * ScheduledPool * Scheduled: 计划中的,定时的 * 执行定时的任务,类似Delay, 可以替代Timer */ public class T10_ScheduledPool { public static void main(String[] args) { ScheduledExecutorService service... 阅读全文
posted @ 2019-10-22 14:49 我爱si搬砖 阅读(571) 评论(0) 推荐(0) 编辑
摘要: /** * SingleThreadPool * 线程池中只有一个线程 * 作用,保证线程执行的时序性 */ public class T09_SingleThreadPool { public static void main(String[] args) { ExecutorService service = Executors.newSingleThr... 阅读全文
posted @ 2019-10-22 14:46 我爱si搬砖 阅读(316) 评论(0) 推荐(0) 编辑
摘要: /** * CachedThreadPool * 可缓存的线程 * 当有个请求进入线程池内, 线程池将会启用一个线程 * 当再次有个请求进入线程池内, 并且上个线程未结束, 仍然会启用一个线程 * 当有线程执行完毕后,这个线程不会被清除, 而是被缓存,当有请求进入时, 直接使用缓存线程调用 * 跟 fixedThreadPool 类似, 只不过没有上限(最多Integer最大值... 阅读全文
posted @ 2019-10-22 14:44 我爱si搬砖 阅读(555) 评论(0) 推荐(0) 编辑
摘要: /** * T12_ForkJoinPool 分而治之 * Fork: 分叉 * Join: 合并 * * 将一个任务拆分多个任务执行(可以无限切分),然后将结果合并 * * 比如大量的并行计算, 如下: 求100_0000个数字之和, 使用多线程 */ public class T12_ForkJoinPool { static int[] nums = new int[100_0000]; s 阅读全文
posted @ 2019-10-22 14:40 我爱si搬砖 阅读(387) 评论(0) 推荐(0) 编辑
摘要: /** * WorkStealingPool * 工作窃取线程池 * * 假设共有三个线程同时执行, A, B, C * 当A,B线程池尚未处理任务结束,而C已经处理完毕,则C线程会从A或者B中窃取任务执行,这就叫工作窃取 * 假如A线程中的队列里面分配了5个任务,而B线程的队列中分配了1个任务,当B线程执行完任务后,它会主动的去A线程中窃取其他的任务进行执行 * WorkStealingPool 阅读全文
posted @ 2019-10-22 14:39 我爱si搬砖 阅读(3307) 评论(1) 推荐(0) 编辑