Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring batch 具有提交间隔的Spring批处理问题_Spring Batch - Fatal编程技术网

Spring batch 具有提交间隔的Spring批处理问题

Spring batch 具有提交间隔的Spring批处理问题,spring-batch,Spring Batch,我已经编写了一个spring批处理程序,在其中我实现了自定义读写器类。 当我保持提交间隔时,多个记录会重复到提交间隔大小。 例如,我正在以 Id、名称 1,阿卡什 2、约翰 3,Daksh 和提交间隔=“2” 在这种情况下,writer以 1,阿卡什 1,阿卡什 3,Daksh (第一条记录重复到提交间隔,然后是提交间隔后的记录,中间记录在某处被跳过) 当提交间隔=1时,每件事情都可以正常工作,但会对性能产生巨大影响。 请告知 代码片段如下所示: public class PGPFlatFile

我已经编写了一个spring批处理程序,在其中我实现了自定义读写器类。
当我保持提交间隔时,多个记录会重复到提交间隔大小。

例如,我正在以
Id、名称
1,阿卡什
2、约翰
3,Daksh

和提交间隔=“2”
在这种情况下,writer以
1,阿卡什
1,阿卡什
3,Daksh

(第一条记录重复到提交间隔,然后是提交间隔后的记录,中间记录在某处被跳过)

当提交间隔=1时,每件事情都可以正常工作,但会对性能产生巨大影响。

请告知
代码片段如下所示:

public class PGPFlatFileItemReader extends FlatFileItemReader<Object> 
implements InitializingBean {

/*
 * if this flag is true that means file
 * is commpressed
 */
private boolean isCompressed = true; 
private String passphrase;
private String secretKeyFilePath;
private String publicKeyFilePath;
private String publicKeyUserId;
private String inputFilePath;

public PGPFlatFileItemReader() {
    SecurityUtil.loadSecuritySetting();
}

/**
 * @return the isCompressed
 */
public boolean isCompressed() {
    return isCompressed;
}

/**
 * @param isCompressed
 *            the isCompressed to set
 */
public void setCompressed(boolean isCompressed) {
    this.isCompressed = isCompressed;
}

/**
 * @return the passphrase
 */
public String getPassphrase() {
    return passphrase;
}

/**
 * @param passphrase
 *            the passphrase to set
 */
public void setPassphrase(String passphrase) {
    this.passphrase = passphrase;
}

/**
 * @return the secretKeyFilePath
 */
public String getSecretKeyFilePath() {
    return secretKeyFilePath;
}

/**
 * @param secretKeyFilePath
 *            the secretKeyFilePath to set
 */
public void setSecretKeyFilePath(String secretKeyFilePath) {
    this.secretKeyFilePath = secretKeyFilePath;
}

/**
 * @return the publicKeyFilePath
 */
public String getPublicKeyFilePath() {
    return publicKeyFilePath;
}

/**
 * @param publicKeyFilePath
 *            the publicKeyFilePath to set
 */
public void setPublicKeyFilePath(String publicKeyFilePath) {
    this.publicKeyFilePath = publicKeyFilePath;
}

/**
 * @return the publicKeyUserId
 */
public String getPublicKeyUserId() {
    return publicKeyUserId;
}

/**
 * @param publicKeyUserId
 *            the publicKeyUserId to set
 */
public void setPublicKeyUserId(String publicKeyUserId) {
    this.publicKeyUserId = publicKeyUserId;
}

/**
 * @return the inputFilePath
 */
public String getInputFilePath() {
    return inputFilePath;
}

/**
 * @param inputFilePath
 *            the inputFilePath to set
 */
public void setInputFilePath(String inputFilePath) {
    this.inputFilePath = inputFilePath;
}

@Override
public void afterPropertiesSet() throws Exception {
    super.afterPropertiesSet();
    FileDecrypter fileDecrypter = new FileDecrypter();
    if (this.isCompressed) {

        this.uncompressFile(fileDecrypter.decryptFile(inputFilePath, secretKeyFilePath, passphrase.toCharArray(),
                "sample.txt", true, 2));

        inputFilePath = inputFilePath + Constants.INBOUND_UNC_FILE;

    }

    InputStream clearStream = fileDecrypter.decryptFile(inputFilePath, secretKeyFilePath, passphrase.toCharArray(),
            "sample.txt", false, 2);

    InputStreamResource in = new InputStreamResource(clearStream);

    this.setResource(in);

}

private void uncompressFile(InputStream unc)
        throws IOException, NoSuchProviderException, PGPException, SpringBatchException {

    BufferedReader bufferRead = new BufferedReader(new InputStreamReader(unc));

    ArrayList<String> rawdata = new ArrayList<String>();
    FileEncrypter fileEncrypter = new FileEncrypter();

    PGPPublicKey encKey;

    String outFileName = inputFilePath + Constants.INBOUND_UNC_FILE;

    if (JavaUtil.isObjectNull(publicKeyFilePath)) {

        throw new SpringBatchException(ExceptionCodes.PUBLIC_KEY_NOTFOUND, "For Public Key Path");

    }
    encKey = SecurityUtil.readPublicKey(publicKeyFilePath, publicKeyUserId);

    String line = bufferRead.readLine();

    while (line != null) {
        if (rawdata.size() < Constants.batchSize) {
            rawdata.add(line + "\n");
        } else if (rawdata.size() == Constants.batchSize) {
            rawdata.add(line + "\n");
            StringBuilder RecordsBuilder = new StringBuilder();
            for (String record : rawdata) {
                RecordsBuilder.append(record);
            }
            fileEncrypter.encryptBigText(outFileName, RecordsBuilder.toString(), encKey, false, true);
            rawdata.clear();
        }
        line = bufferRead.readLine();
        if (line == null) {
            for (String record : rawdata) {

                if (rawdata.size() > 0) {
                    fileEncrypter.encryptBigText(outFileName, record, encKey, false, true);
                }
            }
            rawdata.clear();
        }
    }

    if (rawdata.size() > 0) {
        for (String record : rawdata) {
            fileEncrypter.encryptBigText(outFileName, record, encKey, false, true);
        }
    }

    FileEncrypter.setCalledForFirstTime(false);
    FileEncrypter.closeStreams();
    if (!JavaUtil.isObjectNull(FileEncrypter.fBufferedOut)) {
        FileEncrypter.fBufferedOut.close();
    }
}

}
public类PGPFlatFileItemReader扩展了FlatFileItemReader
实现初始化bean{
/*
*如果此标志为true,则表示文件
*按下按钮
*/
私有布尔值isCompressed=true;
私有字符串密码短语;
私有字符串secretKeyFilePath;
私有字符串publicKeyFilePath;
私有字符串publicKeyUserId;
私有字符串输入文件路径;
公共PGPFlatFileItemReader(){
SecurityUtil.loadSecuritySetting();
}
/**
*@返回已压缩的文件
*/
公共布尔值是压缩的(){
返回被压缩;
}
/**
*@param已压缩
*这是压缩设置
*/
public void setCompressed(boolean isCompressed){
this.isCompressed=isCompressed;
}
/**
*@返回密码短语
*/
公共字符串getPassphrase(){
返回密码短语;
}
/**
*@param密码短语
*要设置的密码短语
*/
公共无效设置密码短语(字符串密码短语){
this.passphrase=密码短语;
}
/**
*@返回secretKeyFilePath
*/
公共字符串getSecretKeyFilePath(){
返回secretKeyFilePath;
}
/**
*@param secretKeyFilePath
*要设置的secretKeyFilePath
*/
public void setSecretKeyFilePath(字符串secretKeyFilePath){
this.secretKeyFilePath=secretKeyFilePath;
}
/**
*@返回publicKeyFilePath
*/
公共字符串getPublicKeyFilePath(){
返回publicKeyFilePath;
}
/**
*@param publicKeyFilePath
*要设置的publicKeyFilePath
*/
public void setPublicKeyFilePath(字符串publicKeyFilePath){
this.publicKeyFilePath=publicKeyFilePath;
}
/**
*@返回publicKeyUserId
*/
公共字符串getPublicKeyUserId(){
返回publicKeyUserId;
}
/**
*@param publicKeyUserId
*要设置的publicKeyUserId
*/
public void setPublicKeyUserId(字符串publicKeyUserId){
this.publicKeyUserId=publicKeyUserId;
}
/**
*@返回inputFilePath
*/
公共字符串getInputFilePath(){
返回inputFilePath;
}
/**
*@param inputFilePath
*要设置的inputFilePath
*/
public void setInputFilePath(字符串inputFilePath){
this.inputFilePath=inputFilePath;
}
@凌驾
public void afterPropertieSet()引发异常{
super.afterPropertiesSet();
FileDecrypter FileDecrypter=新的FileDecrypter();
如果(此.isCompressed){
此.uncompressFile(fileDecrypter.decryptFile)(inputFilePath、secretKeyFilePath、passphrase.toCharArray(),
“sample.txt”,正确,2);
inputFilePath=inputFilePath+Constants.INBOUND\u UNC\u文件;
}
InputStream clearStream=fileDecrypter.decryptFile(inputFilePath,secretKeyFilePath,passphrase.ToCharray(),
“sample.txt”,假,2);
InputStreamResource in=新的InputStreamResource(clearStream);
此.setResource(in);
}
私有void解压缩文件(InputStream unc)
抛出IOException、NoSuchProviderException、PGPEException、SpringBatchException{
BufferedReader bufferRead=新的BufferedReader(新的InputStreamReader(unc));
ArrayList rawdata=新的ArrayList();
FileEncrypter FileEncrypter=新的FileEncrypter();
PGPPublicKey;
字符串outFileName=inputFilePath+Constants.INBOUND\u UNC\u文件;
if(JavaUtil.isObjectNull(publicKeyFilePath)){
抛出新的SpringBatchException(ExceptionCodes.PUBLIC_KEY_NOTFOUND,“用于公钥路径”);
}
encKey=SecurityUtil.readPublicKey(publicKeyFilePath,publicKeyUserId);
String line=bufferRead.readLine();
while(行!=null){
if(rawdata.size()0){
encryptBigText(outFileName、记录、encKey、false、true);
}
}
rawdata.clear();
}
}
如果(rawdata.size()>0){
for(字符串记录:rawdata){
encryptBigText(outFileName、记录、encKey、false、true);
}
}
FileEncrypter.setCalledForFirstTime(false);
FileEncrypter.closeStreams();
如果(!JavaUtil.isObjectNull(FileEncrypter.fBufferedOut)){
FileEncrypter.fBufferedOut.close();
}
}
}

您使用的是什么
ItemReader
?请提供任何相关的代码和配置,以便我们能够帮助诊断。@MichaelMinella:添加了有问题的代码段。