org.apache.edgent.function.Functions.synchronizedFunction()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(1.6k)|赞(0)|评价(0)|浏览(87)

本文整理了Java中org.apache.edgent.function.Functions.synchronizedFunction()方法的一些代码示例,展示了Functions.synchronizedFunction()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Functions.synchronizedFunction()方法的具体详情如下:
包路径:org.apache.edgent.function.Functions
类名称:Functions
方法名:synchronizedFunction

Functions.synchronizedFunction介绍

[英]Return a thread-safe version of a Function function. If the function is guaranteed to be immutable (stateless) then the function is returned, as it is thread safe, otherwise a wrapper is returned that grabs synchronization on function when calling Function#apply(Object).
If function implements AutoCloseable then the function is assumed to be stateful and a thread-safe version is returned.
[中]返回函数的线程安全版本。如果函数被保证是不可变的(无状态的),那么函数将返回,因为它是线程安全的,否则将返回一个包装器,在调用函数#apply(Object)时获取函数上的同步。
如果函数实现了AutoCloseable,则假定该函数是有状态的,并返回线程安全版本。

代码示例

代码示例来源:origin: org.apache.edgent/edgent-spi-topology

@Override
public <U> TStream<U> map(Function<T, U> mapper) {
  mapper = synchronizedFunction(mapper);
  return connectPipe(new Map<T, U>(mapper));
}

代码示例来源:origin: apache/incubator-edgent

@Override
public <U> TStream<U> map(Function<T, U> mapper) {
  mapper = synchronizedFunction(mapper);
  return connectPipe(new Map<T, U>(mapper));
}

代码示例来源:origin: apache/incubator-edgent

assertSame(f1, Functions.synchronizedFunction(f1));
assertSame(f2, Functions.synchronizedFunction(f2));
assertSame(f3, Functions.synchronizedFunction(f3));
assertNotSame(f4, Functions.synchronizedFunction(f4));
Function<Integer,Integer> f5s = Functions.synchronizedFunction(f5);
assertNotSame(f5, f5s);
int r5s = f5s.apply(18);
assertNotSame(f6, Functions.synchronizedFunction(f6));

相关文章