V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  pwrliang  ›  全部回复第 16 页 / 共 19 页
回复总数  380
1 ... 8  9  10  11  12  13  14  15  16  17 ... 19  
2018-08-17 09:18:47 +08:00
回复了 choice4 创建的主题 程序员 惯性动作怎么破
Ctrl+l 是一样的效果
2018-08-08 10:57:49 +08:00
回复了 Love4Taylor 创建的主题 Android Android 9.0 Pie 正式版已释出
@xuhaoyangx 是 Pixel2 的
2018-08-08 04:57:26 +08:00
回复了 Love4Taylor 创建的主题 Android Android 9.0 Pie 正式版已释出
@xuhaoyangx @honeycomb 刚刚 check 了下,收到 9.0 更新啦:-)
2018-08-07 02:36:25 +08:00
回复了 Love4Taylor 创建的主题 Android Android 9.0 Pie 正式版已释出
怎么从 8.0 升级到 9 ?需要加入 beta 计划吗?我点击 check update 没有提示要升级啊
同感,我还以为是脑子出问题了。
2018-07-30 11:50:13 +08:00
回复了 337136897 创建的主题 问与答 如何寻找一个能够出国工作的机会?
我在美国带了半年多做 research,感觉生活好无聊,又不会开车,哪里都不能去。好吃的也少…
2018-07-30 11:48:34 +08:00
回复了 engineer9 创建的主题 Hadoop hadoop or spark 大数据去重(10 亿)
尝试实现下 cuckoo hash ? https://en.m.wikipedia.org/wiki/Cuckoo_hashing
第二种做法会把字符串存储在 text segment,是只读的
2018-07-30 00:50:52 +08:00
回复了 Ultraman 创建的主题 随想 会让你觉得“遗憾没有生活在那个时代”的人物?
想回到 60s 看看 Elvis, The Beatles
2018-07-25 10:56:30 +08:00
回复了 lily233 创建的主题 问与答 捡到了别人的身份证和银行卡,怎么找到失主联系方式?
路不拾遗,放回原处。施主能不能找到就随缘吧。
2018-07-20 12:27:15 +08:00
回复了 lzhCoooder 创建的主题 NVIDIA 最近想上手 CUDA,求推荐显卡
我也写 CUDA,一般用 1080 足够了。有钱可以上最新的 Volta 架构。
2018-07-20 12:23:45 +08:00
回复了 panzhougeek 创建的主题 问与答 V 站有人喜欢硬摇滚么?最喜欢哪首歌?
AC/DC 的 Back in black
2018-07-20 08:00:00 +08:00
回复了 WildCat 创建的主题 Turi 这个节点叫 Turi Create 更合适
想知道 graphlab 被苹果收购后开发得 turi create,真的有公司在用吗?有公司招 graph computation 的人吗?
2018-07-19 22:13:26 +08:00
回复了 zhady009 创建的主题 Java 用 BlockingQueue 出现了一个无法解释的问题
@pwrliang 刚刚结果粘贴错了
--------------------------------------------------
seq:1producer01:produced =====> 45
seq:2customer01:consumed:45
seq:3producer01:produced =====> 20
seq:4customer01:consumed:20
seq:5producer01:produced =====> 78
seq:6customer01:consumed:78
seq:7producer01:produced =====> 45
seq:8customer01:consumed:45
seq:9producer01:produced =====> 90
seq:10customer01:consumed:90
seq:11producer01:produced =====> 57
seq:12customer01:consumed:57
2018-07-19 22:12:15 +08:00
回复了 zhady009 创建的主题 Java 用 BlockingQueue 出现了一个无法解释的问题
这回可以了,要保证 put+sysout, take+sysout 是原子性的,只能加个全局锁。

public class Test {

public static void main(String[] args) throws IOException, InterruptedException {
Lock lock = new ReentrantLock();
BlockingQueue<Integer> bq = new LinkedBlockingQueue<Integer>(1);

AtomicInteger seq =new AtomicInteger(0);

Producer p1 = new Producer(bq,seq,lock);
p1.setName("producer01");
Customer c1 = new Customer(bq,seq,lock);
c1.setName("customer01");
p1.start();
c1.start();
}

}

class Producer extends Thread {
AtomicInteger seq;
Lock lock;
private BlockingQueue<Integer> bq;
public Producer(BlockingQueue<Integer> bq,AtomicInteger seq,Lock lock) {
this.bq = bq;
this.seq = seq;
this.lock = lock;
}

@Override
public void run() {
while (true) {
try {
if(bq.size()==1)continue;
lock.lock();
bq.put(produce());
lock.unlock();
} catch (InterruptedException e) {
e.printStackTrace();
}

}
}

private Integer produce() {
Integer number = (new Random().nextInt(100));
int sid=seq.addAndGet(1);
System.out.println("seq:"+sid+getName() + ":produced =====> " + number);
System.out.flush();
return number;
}
}

class Customer extends Thread {
AtomicInteger seq;
private BlockingQueue<Integer> bq;
Lock lock;

public Customer(BlockingQueue<Integer> bq,AtomicInteger seq,Lock lock) {
this.bq = bq;
this.seq = seq;
this.lock = lock;
}

@Override
public void run() {
while (true) {
try {
if (bq.size()==0)continue;
lock.lock();
consume();
lock.unlock();
} catch (Exception e) {
e.printStackTrace();
}
}
}

private void consume() throws InterruptedException {
int tk = bq.take();
int sid=seq.addAndGet(1);
System.out.println("seq:" + sid + getName() + ":consumed:" + tk);
System.out.flush();
}
}

-------------------------------------------------

public class Test {

public static void main(String[] args) throws IOException, InterruptedException {
Lock lock = new ReentrantLock();
BlockingQueue<Integer> bq = new LinkedBlockingQueue<Integer>(1);

AtomicInteger seq =new AtomicInteger(0);

Producer p1 = new Producer(bq,seq,lock);
p1.setName("producer01");
Customer c1 = new Customer(bq,seq,lock);
c1.setName("customer01");
p1.start();
c1.start();
}

}

class Producer extends Thread {
AtomicInteger seq;
Lock lock;
private BlockingQueue<Integer> bq;
public Producer(BlockingQueue<Integer> bq,AtomicInteger seq,Lock lock) {
this.bq = bq;
this.seq = seq;
this.lock = lock;
}

@Override
public void run() {
while (true) {
try {
if(bq.size()==1)continue;
lock.lock();
bq.put(produce());
lock.unlock();
} catch (InterruptedException e) {
e.printStackTrace();
}

}
}

private Integer produce() {
Integer number = (new Random().nextInt(100));
int sid=seq.addAndGet(1);
System.out.println("seq:"+sid+getName() + ":produced =====> " + number);
System.out.flush();
return number;
}
}

class Customer extends Thread {
AtomicInteger seq;
private BlockingQueue<Integer> bq;
Lock lock;

public Customer(BlockingQueue<Integer> bq,AtomicInteger seq,Lock lock) {
this.bq = bq;
this.seq = seq;
this.lock = lock;
}

@Override
public void run() {
while (true) {
try {
if (bq.size()==0)continue;
lock.lock();
consume();
lock.unlock();
} catch (Exception e) {
e.printStackTrace();
}
}
}

private void consume() throws InterruptedException {
int tk = bq.take();
int sid=seq.addAndGet(1);
System.out.println("seq:" + sid + getName() + ":consumed:" + tk);
System.out.flush();
}
}
2018-07-19 00:26:25 +08:00
回复了 zhady009 创建的主题 Java 用 BlockingQueue 出现了一个无法解释的问题
我一开始也是认为 sysout 的问题,但是我统计了调用序列,也是交替的啊。
import java.io.IOException;
import java.util.Random;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;

public class Test {

public static void main(String[] args) throws IOException, InterruptedException {

BlockingQueue<Integer> bq = new LinkedBlockingQueue<Integer>(1);

AtomicInteger seq =new AtomicInteger(0);

Producer p1 = new Producer(bq,seq);
p1.setName("producer01");
Customer c1 = new Customer(bq,seq);
c1.setName("customer01");
p1.start();
c1.start();
}

}

class Producer extends Thread {
AtomicInteger seq;
private BlockingQueue<Integer> bq;
public Producer(BlockingQueue<Integer> bq,AtomicInteger seq) {
this.bq = bq;
this.seq = seq;
}

@Override
public void run() {
while (true) {
try {
bq.put(produce());
// Thread.sleep(0,1);
} catch (InterruptedException e) {
e.printStackTrace();
}

}
}

private Integer produce() {
Integer number = (new Random().nextInt(100));
int sid=seq.addAndGet(1);
System.out.println("seq:"+sid+getName() + ":produced =====> " + number);
System.out.flush();
return number;
}
}

class Customer extends Thread {
AtomicInteger seq;
private BlockingQueue<Integer> bq;

public Customer(BlockingQueue<Integer> bq,AtomicInteger seq) {
this.bq = bq;
this.seq = seq;
}

@Override
public void run() {
while (true) {
try {
consume();
} catch (Exception e) {
e.printStackTrace();
}
}
}

private void consume() throws InterruptedException {
int sid=seq.addAndGet(1);
System.out.println("seq:" + sid + getName() + ":consumed:" + bq.take());
System.out.flush();
}
}





----------------------------------------


seq:2producer01:produced =====> 44
seq:3producer01:produced =====> 97
seq:1customer01:consumed:44
seq:4customer01:consumed:97
seq:5producer01:produced =====> 19
seq:7producer01:produced =====> 88
seq:6customer01:consumed:19
seq:8producer01:produced =====> 90
seq:9customer01:consumed:88
seq:10producer01:produced =====> 93
seq:11customer01:consumed:90
seq:12producer01:produced =====> 40
2018-07-18 12:02:08 +08:00
回复了 w0nglend 创建的主题 问与答 亚马逊 prime 节有啥推荐买的么
Chromebook 啊~!!!
@fayloue @taresky 我找到了当年记录的截图,(还发生过另一次更夸张,但是没截图了)。手机是小米 4 全网通 3g 版,大家可以算下速率

http://imgsrc.baidu.com/forum/w%3D580/sign=752c8634b3a1cd1105b672288913c8b0/6f945bb5c9ea15cebb23820dbf003af33b87b210.jpg
1 ... 8  9  10  11  12  13  14  15  16  17 ... 19  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3704 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 33ms · UTC 00:59 · PVG 08:59 · LAX 16:59 · JFK 19:59
Developed with CodeLauncher
♥ Do have faith in what you're doing.