Hi,
应该是可以的。
--
Best!
Xuyang
在 2024-08-29 15:00:54,"刘仲诺" <[email protected]> 写道:
>您好,我目前使用的是DataStream API,代码如下:
>public class BytesProcessor extends ProcessWindowFunction<Tuple2<Long,
>Long>, BytesResult, String, TimeWindow> {
> private final BytesResult bytesResult = new BytesResult();
> @Override
> public void process(String key,
>
> ProcessWindowFunction<Tuple2<Long, Long>, BytesResult, String,
>TimeWindow>.Context context,
>
> Iterable<Tuple2<Long, Long>> accumulator,
>
> Collector<BytesResult> out) throws Exception {
> Tuple2<Long, Long> result =
>accumulator.iterator().next();
>// BytesResult bytesResult = new BytesResult();
> bytesResult.setChannelId(key);
> bytesResult.setLastHopRecvBytes(result.f0);
> bytesResult.setNextHopSendBytes(result.f1);
>
>bytesResult.setCurrentTime(context.window().getStart());
> if (!Objects.equals(result.f0, result.f1)) {
> out.collect(bytesResult);
> }
> }
>}
>
>我在这里用算子实例的bytesResult变量代替了每次输出新建的bytesResult,这样的做法是否安全呢
>
>
>
>
>------------------ 原始邮件 ------------------
>发件人:
> "user-zh"
>
><[email protected]>;
>发送时间: 2024年8月29日(星期四) 下午2:56
>收件人: "user-zh"<[email protected]>;
>
>主题: Re:flink对象重用问题询问
>
>
>
>Hi,
>
>在算子output时,是可以复用row的,在flink sql所转化的operator中,就有很多类似的做法,具体可以参考[1][2]
>
>
>
>
>[1]
>https://github.com/apache/flink/blob/576ec2b9361a3f8d58fb22b998b0ca7c3c8cf10e/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/join/stream/StreamingJoinOperator.java#L45
>
>[2]
>https://github.com/apache/flink/blob/576ec2b9361a3f8d58fb22b998b0ca7c3c8cf10e/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/aggregate/GroupAggFunction.java#L66
>
>
>
>
>--
>
> Best!
> Xuyang
>
>
>
>
>
>在 2024-08-29 12:42:28,"刘仲诺" <[email protected]> 写道:
>>您好,目前我正在开发flink流计算程序,请问flink在算子函数中是否允许对象重用呢,比如我在构造输出记录时,不是每次都新建一条记录,而是只新建一个记录对象作为算子函数实例的成员,在构造输出记录时只更改这个对象的属性然后进行输出,请问这样的做法在flink中是安全的吗?我想进行这种操作的主要目的是减少对象创建