vvtf 最近的时间轴更新
vvtf

vvtf

V2EX 第 585406 号会员,加入于 2022-06-21 13:47:25 +08:00
vvtf 最近回复了
161 天前
回复了 JinTianYi456 创建的主题 Java RedissonClient, 这种 lock 风格有隐患吗?
public final class RLockCloseable implements AutoCloseable {

private RLock lock;
private boolean locked;

public RLockCloseable(RLock lock) {
Objects.nonNull(lock);
this.lock = lock;
}

public static RLockCloseable of(RLock lock) {
return new RLockCloseable(lock);
}

public static void ifLocked(RLock lock, Consumer<Void> fn) {
try (RLockCloseable _lock = new RLockCloseable(lock)) {
if (_lock.tryLock()) {
fn.accept(null);
}
}
}

public boolean tryLock() {
// or use isHeldByCurrentThread
return locked = lock.tryLock();
}

public void close() {
if (locked) lock.unlock();
}

}


// usage
//1.
try (RLockCloseable lock = redisson.getLock("key")) {
if (lock.tryLock()) {
// TODO
}
}

//2.
RLockCloseable.ifLocked(redisson.getLock("key"), _t -> {
// TODO
});
intel nuc x15.
161 天前
回复了 cy18 创建的主题 硬件 求推荐高性价比大屏幕笔记本
要不看下 intel nux x15. 硬盘和内存自己装. i7, rtx3070, 2.5k, 7k.
189 天前
回复了 8629 创建的主题 Java 请教下 Java 热替换代码的技术
1. 通过 Agent 拿到 Instrumentation
2. 通过 Instrumentation#redefineClasses 替换类即可.
212 天前
回复了 dtgxx 创建的主题 问与答 flink 去重问题请教
if (value.toLowerCase().indexOf("a") > -1)
这个判断是我的测试代码,
你可以改成你的 json 方式判断.
212 天前
回复了 dtgxx 创建的主题 问与答 flink 去重问题请教
2 种思路,
1 是使用滑动窗口, 窗口大小为 24h,
然后去重;

2 是记录一个上次 a 出现的时间, 如果大于 24h 就重新计算, 小于 24h 就跳过.

下面是方法 1 的代码:
ds
.windowAll(TumblingProcessingTimeWindows.of(Time.hours(24)))
.process(new ProcessAllWindowFunction<String, String, TimeWindow>() {
private static final long serialVersionUID = 1L;

@Override
public void process(ProcessAllWindowFunction<String, String,
TimeWindow>.Context ctx,
Iterable<String> values, Collector<String> out) throws Exception {
boolean repeat = false;
for (String value : values) {
if (value.toLowerCase().indexOf("a") > -1) {
if (repeat) {
continue;
}
repeat = true;
}
out.collect(value);
}

}
})
.print();
216 天前
回复了 vvtf 创建的主题 程序员 请教一个 IP 代理访问问题
@defunct9
我试了 alias,
但是在 HTTP 服务获取到的 IP 地址始终是 31
232 天前
回复了 leiuu 创建的主题 程序员 maven 使用体验很痛苦
gradle 和 npm 的包管理是我见过最恶心的.只讨论包管理.
238 天前
回复了 shadow1949 创建的主题 程序员 SQL 苦手来请教各位大佬了。
# 5 天, 因为去掉周末, 所以倒推 7 天, 10 天倒推 14 天
select
avg(num)
from table_name
where `date`>date_sub({someday},interval 7 day)
and `date`<={someday} and weekday(`date`)<5;

# 10 天
select
avg(num)
from table_name
where `date`>date_sub({someday},interval 14 day)
and `date`<={someday} and weekday(`date`)<5;
```java

interface Rule<T extends S> {

T run(T... args);

default boolean enabled() {
return true;
}

default boolean async() {
return false;
}

}

@Order(0)
@Component
class RuleA implements Rule<SomeA> {

T run(T... args) {
// TODO
}

boolean async() {return true;}

}

@Component
class RuleChain {
@Autowired
private List<Rule> rules;

static ExecutorService pool = xxxx;

public void run(T... args) {

rules.stream().filter(Rule::enabled).filter(Rule::async).forEach(rule -> pool.execute(rule.run()););
rules.stream().filter(Rule::enabled).filter(rule -> !rule.async()).forEach(Rule::run);

}

}

```
关于   ·   帮助文档   ·   博客   ·   nftychat   ·   API   ·   FAQ   ·   我们的愿景   ·   广告投放   ·   实用小工具   ·   2534 人在线   最高记录 5556   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 22ms · UTC 13:06 · PVG 21:06 · LAX 06:06 · JFK 09:06
Developed with CodeLauncher
♥ Do have faith in what you're doing.