-
问一个线程同步的问题
2017-04-21 13:18纠正一下 take 漏了循环 ,只取了一次。。。。。。
public class BlockingQTest {
public static void main(String [] as) throws InterruptedException {
BlockingQ blockingQ = new BlockingQ();
Thread offerThread = new Thread(new OfferTask(blockingQ),"offerThread");
Thread takeThread = new Thread(new TakeTask(blockingQ),"takeThread");
offerThread.start();
takeThread.start();
}
}class TakeTask implements Runnable{ private BlockingQ blockingQ; public TakeTask(BlockingQ blockingQ){ this.blockingQ = blockingQ; } @Override public void run() { try { while(true) { Object o = blockingQ.take(); System.out.println("take:" + o); } } catch (InterruptedException e) { e.printStackTrace(); } } } class OfferTask implements Runnable{ private BlockingQ blockingQ; public OfferTask(BlockingQ blockingQ){ this.blockingQ = blockingQ; } @Override public void run() { try { for (int i=0; i < 100; i++){ blockingQ.offer(i); } } catch (InterruptedException e) { e.printStackTrace(); } } }
-
问一个线程同步的问题
2017-04-21 12:51我做了个测试:
public class BlockingQTest { public static void main(String [] as) throws InterruptedException { BlockingQ blockingQ = new BlockingQ(); Thread offerThread = new Thread(new OfferTask(blockingQ), "offerThread"); Thread takeThread = new Thread(new TakeTask(blockingQ), "takeThread"); offerThread.start(); takeThread.start(); } } class TakeTask implements Runnable{ private BlockingQ blockingQ; public TakeTask(BlockingQ blockingQ){ this.blockingQ = blockingQ; } @Override public void run() { try { Object o = blockingQ.take(); System.out.println("take:" + o); } catch (InterruptedException e) { e.printStackTrace(); } } } class OfferTask implements Runnable{ private BlockingQ blockingQ; public OfferTask(BlockingQ blockingQ){ this.blockingQ = blockingQ; } @Override public void run() { try { for (int i=0; i < 100; i++){ blockingQ.offer(i); } } catch (InterruptedException e) { e.printStackTrace(); } } }
确实是不会释放锁的,我写的测试方式有问题吗 ? 死锁了
-
微信程序如何灰度发布
2017-01-20 11:02我们是有一个策略系统的,策略系统可以配置用户的一些信息,比如男女、单双号、渠道(每个用户的渠道标识)等,然后匹配的才走某个逻辑,不匹配就不处理了。灰度完成,再把策略应用到全渠道,不过这是属于编码层面的控制。