![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
并发与测试
qq_22120511
这个作者很懒,什么都没留下…
展开
-
模拟进入房间的人数多于房间要求人数
package room;/** * A模拟一个房间进了人数过多 * * @author Administrator * */public class RoomA { public static int pNum = 0; public static void inc() { try { Thread.sleep(1); } catch (Exception...原创 2018-07-10 21:11:22 · 190 阅读 · 0 评论 -
模拟一个人进入了多个房间
package room;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;/** * B模拟一个人进了多个房间 * @author Administrator * */public class RoomB { /** * ...原创 2018-07-10 21:43:17 · 172 阅读 · 0 评论 -
fast-lost
fast-lostpackage room;import java.util.ArrayList;import java.util.List;public class fastLost { public static void main(String[] args) { final List<Integer> list=new ArrayList<&g...原创 2018-07-10 23:19:40 · 125 阅读 · 0 评论 -
正确的加入房间代码
package room;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;/** * 不同用户进出房间造成异常 * @author Administrator * */public class RoomRight { /** * 人数 */ publi...原创 2018-07-10 23:52:27 · 926 阅读 · 0 评论 -
模拟高并发武将穿装备
package bag;import java.util.HashMap;public class Equipment { static HashMap<Integer, Integer> peopleMap=new HashMap<>(); static HashMap<Integer, Integer> equipMap=new Has...原创 2018-07-11 23:59:32 · 142 阅读 · 0 评论 -
线程遍历list移除数据
package com.my.module;import java.util.List;import java.util.Random;import java.util.concurrent.CopyOnWriteArrayList;import java.util.concurrent.Executors;import java.util.concurrent.ScheduledE...原创 2018-07-23 22:08:58 · 420 阅读 · 0 评论 -
相互调用引发死锁
package com.xinhai.myThread;public class OneThread { private TwoThread two; public synchronized void oneThreadA() { System.out.println("oneThreadA"); try { Thread.sleep(10); } catc...原创 2018-07-17 14:14:04 · 440 阅读 · 0 评论 -
解决动态死锁问题
场景:用户之间相互影响的高并发(如战斗,转账)借助System.identityHashCode和第三把锁package com.xinhai.myThread;public class DealDeadLine { public void transferMoney(Account a, Account b) { synchronized (a) { // 模拟测试...原创 2018-07-17 12:59:08 · 352 阅读 · 0 评论 -
死锁2(动态锁死锁)
package com.xinhai.myThread;public class DeadThread { public void transferMoney(Account a, Account b) { synchronized (a) { try { Thread.sleep(100); } catch (InterruptedException e) {...原创 2018-07-17 11:08:17 · 210 阅读 · 0 评论 -
死锁1
package com.xinhai.myThread;public class DeadThread { private final Object left =new Object(); private final Object right =new Object(); public void leftRight() { synchronized (left) { ...原创 2018-07-17 11:07:55 · 88 阅读 · 0 评论 -
并发不保证多个原子状态变量的同一状态
package test;import java.util.Random;import java.util.concurrent.atomic.AtomicInteger;public class Counter { // public static int count = 0; public static AtomicInteger count = new AtomicInteg...原创 2018-07-17 01:20:49 · 99 阅读 · 0 评论