@Transactional(isolation = Isolation.READ_UNCOMMITTED
, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void insertPhoneAndArea(List<RecordEntity> recordEntityList) {
int tryCount = 0;
OffsetTime startTime = OffsetTime.ofInstant(Instant.now(), ZoneId.systemDefault());
Map<String, List<RecordEntity>> selfGroup = recordEntityList.stream().collect(Collectors.groupingBy(RecordEntity::getSelfNum));
while (0==selfGroup.size()) {
//There has a bug with Jdk Stream to groupBy in One elements ,So have a loop try
selfGroup = recordEntityList.stream().collect(Collectors.groupingBy(RecordEntity::getSelfNum));
tryCount++;
if (tryCount > 20000) {
break;
}
log.info("try to get SelfNum with Stream bug ! count in {} ",tryCount);
}
}
Steps:
- Invoking the method with name insertPhoneAndArea
- Given the same data with variables, with "recordEntityList" in there, and it was not empty
- When I executed the method, the selfGroup was empty and it's size was zero. So I feel strange with the result. It shouldn't be empty because the recordEntityList was not empty.
- I turned on the Debug Mode with IDEA and I was using Alt+LeftClick to execute the code and the result was correct, it wasn't empty.
- So I wrote a try count in the group code, as expected, that code in the loop was approximately random up to 30, and it was a correct result and it was out of the while loop.
I don't know what the bug is.
@Data
public class RecordEntity {
private int id;
/**
* 通话时间
*/
private Date recordTime;
/**
* 持续时长
*/
private Integer duration;
/**
* 通话方式/ 1电话主叫、2电话被叫、3短信主叫、4短信被叫
*/
private Integer recordMode;
/**
* 对方电话号码
*/
private String dialNum;
/**
* 通话地点
*/
private String recordAddress;
/**
* 通话类型/ 1本地、2异地
*/
private Integer recordType;
/**
* 小区编号
*/
private String area;
/**
* 基站号
*/
private String baseStation;
/**
* 交换机号
*/
private String exchange;
/**
* 本机号码
*/
private String selfNum;
/**
* 机主姓名
*/
private String username;
/**
* 机主身份证
*/
private String idNum;
/**
* 通话记录id(唯一)
*/
private String recordId;
/**
* 话单运营商
*/
private Integer operator;
/**
* 对方号码类型(1-手机,2-固话,3-服务号)
*/
private Integer dialNumType;
}