V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  xzg  ›  全部回复第 1 页 / 共 3 页
回复总数  47
1  2  3  
2020-09-08 13:16:40 +08:00
回复了 beryl 创建的主题 程序员 准备走了,如何准备?
我寻思这那边也有微软嘛
2020-05-28 22:19:45 +08:00
回复了 Omooo 创建的主题 酷工作 字节跳动内推啦~
WH 招人工智障不
那就送她拯救者吧
2020-05-14 21:52:44 +08:00
回复了 shicheng1993 创建的主题 机器学习 深度学习装机 4 块 2080TI 配置选择
差不多吧,这是可以报销吗
2020-05-14 21:43:50 +08:00
回复了 cmai 创建的主题 程序员 关于 jmm 内存模型的问题
@cmai 不是很明白,因为 jvm 何时刷新根据 cpu 指令之间的交互、cpu 调度等多种情况,具体你可能要看 jvm 源码了
2020-05-14 21:09:22 +08:00
回复了 cmai 创建的主题 程序员 关于 jmm 内存模型的问题
你把 flag 定义 volatile 试下,我怀疑是子线程修改后没有及时刷新到主内存。
2019-12-20 16:54:29 +08:00
回复了 wuwudeqi 创建的主题 Java netty 的问题
算了 这个排版贼鸡儿恶心
2019-12-20 16:53:27 +08:00
回复了 wuwudeqi 创建的主题 Java netty 的问题
不存在你想的那个问题,设备上报的数据是通过 decoder 是 ChannelInbound 的 handler,你下发的数据 write 是通过 ChannelHandlerContext 写入 ChannelOutbound。下面是官方的图

I/O Request
via Channel or
ChannelHandlerContext
|
+---------------------------------------------------+---------------+
| ChannelPipeline | |
| \|/ |
| +---------------------+ +-----------+----------+ |
| | Inbound Handler N | | Outbound Handler 1 | |
| +----------+----------+ +-----------+----------+ |
| /|\ | |
| | \|/ |
| +----------+----------+ +-----------+----------+ |
| | Inbound Handler N-1 | | Outbound Handler 2 | |
| +----------+----------+ +-----------+----------+ |
| /|\ . |
| . . |
| ChannelHandlerContext.fireIN_EVT() ChannelHandlerContext.OUT_EVT()|
| [ method call] [method call] |
| . . |
| . \|/ |
| +----------+----------+ +-----------+----------+ |
| | Inbound Handler 2 | | Outbound Handler M-1 | |
| +----------+----------+ +-----------+----------+ |
| /|\ | |
| | \|/ |
| +----------+----------+ +-----------+----------+ |
| | Inbound Handler 1 | | Outbound Handler M | |
| +----------+----------+ +-----------+----------+ |
| /|\ | |
+---------------+-----------------------------------+---------------+
| \|/
+---------------+-----------------------------------+---------------+
| | | |
| [ Socket.read() ] [ Socket.write() ] |
| |
| Netty Internal I/O Threads (Transport Implementation) |
+-------------------------------------------------------------------+
2019-12-13 13:04:06 +08:00
回复了 xzg 创建的主题 问与答 2019 版"完全不工作"
@beingbin 看来我不配做个普通人
2019-12-13 13:01:57 +08:00
回复了 xzg 创建的主题 问与答 2019 版"完全不工作"
@alalida 刚看了下大盘今天涨的还可以
2019-12-13 13:01:19 +08:00
回复了 xzg 创建的主题 问与答 2019 版"完全不工作"
@dot2 今天可以回一波了吧
2019-12-02 19:21:34 +08:00
回复了 RingoTC 创建的主题 程序员 2019 年,有没有必要学 Go?
对啊 再等等就 2020 年了 哈哈哈哈
2019-12-02 19:11:05 +08:00
回复了 howardH 创建的主题 职场话题 请问各位哥哥,怎么才能从开发岗转到管理岗
先考个项目管理吧
2019-11-27 18:28:54 +08:00
回复了 Aemple 创建的主题 成都 成都 成都 成都头条有想来的吗
武汉呢
2019-11-20 09:45:33 +08:00
回复了 PonysDad 创建的主题 Java 关于 Builder 模式线程安全的疑问
首先你的两个线程是持有同一个 test 对象来分别调用 write 和 read 方法?如果是那肯定非线程安全,如果是持有 new 的两个 test 对象,那就没影响了
2019-08-30 17:58:07 +08:00
回复了 monetto 创建的主题 Java FutureTask 的 cancel 方法为什么传参 false 依然会终止线程?
复制黏贴
123
true
33

Process finished with exit code 0
修改 catch 代码块抛出异常
} catch (Exception e) {
e.printStackTrace();
}
结果:
java.util.concurrent.CancellationException
at java.util.concurrent.FutureTask.report(FutureTask.java:121)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at cmdt.minibus.model.MainClass.main(MainClass.java:17)
--------------------
源码:
设置 cancel,state 修改

public boolean cancel(boolean mayInterruptIfRunning) {
if (!(state == NEW &&
UNSAFE.compareAndSwapInt(this, stateOffset, NEW,
mayInterruptIfRunning ? INTERRUPTING : CANCELLED)))
return false;
try { // in case call to interrupt throws exception
if (mayInterruptIfRunning) {
try {
Thread t = runner;
if (t != null)
t.interrupt();
} finally { // final state
UNSAFE.putOrderedInt(this, stateOffset, INTERRUPTED);
}
}
} finally {
finishCompletion();
}
return true;
}

result.get 源码:
public V get() throws InterruptedException, ExecutionException {
int s = state;
if (s <= COMPLETING)
s = awaitDone(false, 0L);
return report(s);
}

private V report(int s) throws ExecutionException {
Object x = outcome;
if (s == NORMAL)
return (V)x;
if (s >= CANCELLED)
throw new CancellationException();
throw new ExecutionException((Throwable)x);
}
-----------
这里 result.cancel(false); 将线程终止,修改任务状态 state,后来执行 result.get()根据 state 状态已关闭抛出异常
2019-08-30 17:32:32 +08:00
回复了 wsy190 创建的主题 程序员 写程序这么精简真的好吗?
想起来一次代码走查,用 lambda 写的代码讲了半天(雾)
2019-05-17 13:52:37 +08:00
回复了 heeeedog 创建的主题 程序员 24 岁入行程序员晚吗?
毕业 24 表示 emmmmm。。。。。。
1  2  3  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1000 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 32ms · UTC 22:12 · PVG 06:12 · LAX 15:12 · JFK 18:12
Developed with CodeLauncher
♥ Do have faith in what you're doing.