分布式条件下的Integer使用"=="比较的问题
- Dominant language
- Kotlin
- Stars
- 30.8k
- Forks
- 8k
- PR merge metrics
- No merged PRs in 30d
Description
开发手册中第一部份 编程规约 中第(4)部份OOP规约中第7小条中,关于“对于 Integer var = ? 在-128 至 127 之间的赋值,Integer 对象是在 IntegerCache.cache 产生,
会复用已有对象,这个区间内的 Integer 值可以直接使用==进行判断”的表述,只适用于单机程序,在分布式条件下并不能得到预期的结果。

> 例子,一个spark程序:
`public class Constants {
public static final Integer STATE = 1;
}`
`int state = 1;
Integer state1 = 1;
Integer state2 = new Integer(1);
Integer state3 = Integer.valueOf(1);
SparkSession session = SparkSession.builder().appName("Validate").getOrCreate();
Long count = session.read().limf("/path").select("vin").map(new MapFunction() {
@Override
public String call(Row value) throws Exception {
System.out.println("1 hashcode :" + System.identityHashCode(state1)+" 2:"+System.identityHashCode(state2)+" 3:"+System.identityHashCode(state3)+" constant = " + System.identityHashCode(Constants.STATE.hashCode()));
System.out.println((state == Constants.STATE) + " 1:" + (state1 == Constants.STATE) + " 2:" + (state2 == Constants.STATE) + " 3:" + (state3 == Constants.STATE));
Thread.sleep(100000);
return value.mkString();
}
}, Encoders.STRING())
//whatever action
.count();`
> 测试结果如下:
并没有得到预期的结果
Contributor guide
No contributing guide indexed for this repository
Research direction
Open the development manual at Programming Specifications, OOP Specifications, item 7, and compare its Integer comparison wording with the supplied Spark example and results. Clarify the distributed-execution limitation in that section. The work is done when the manual no longer presents cached Integer identity comparison as generally valid in distributed programs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100