title: Multi Thread zip4j
body: <p>zip4j is a great library. But i run into a problem when using it in a class that uses a thread. The zip4j method is called from a class that implements thread and sometimes (not always) it leaves files uncompress and somtimes there are leftofer files with the extension *.zip345. Also the process returns net.lingala.zip4j.exception.ZipException: cannot rename modified zip file.</p>
  
  <p>The method zip4jProcess is called from the class public method. Class name is: <code>SZipInterface.class</code></p>
  
  <p>The <code>SZipInterface.class</code> is initialized in the thread class ex: ThreadObj.class and instantiated per thread. No static method is used.</p>
  
  <p>What is the cause of the problems? How do you fix it? Is zip4j thread safe?</p>
  
  <p>Method:</p>
  
  <pre><code>    private int zip4jProcess() {
      int status = 0;
      if (null != getInFiles() &amp;&amp; getInFiles().length &gt; 0) {
          for (String file : getInFiles()) {
              File sourceFile = new File(file);
              ZipFile zipFile = null;
              ZipParameters zipParams = new ZipParameters();
              if (getPassword() != null
                      &amp;&amp; !getPassword().trim().equalsIgnoreCase("")) {
                  zipParams.setPassword(getPassword());
                  zipParams.setEncryptFiles(true);
                  zipParams
                          .setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);
  
              }
              zipParams
                      .setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
  
              if (sourceFile.exists()) {
                  try {
                      zipFile = new ZipFile(getZipFileName());
                      if (zipFile.getFile().exists()) {
                          zipFile.addFile(sourceFile, zipParams);
                          if (log.isDebugEnabled()) {
                              log.debug("Adding: " + sourceFile.getName()
                                      + " to " + zipFile.getFile().getName()
                                      + " Pass: " + getPassword());
                          }
                      } else {
                          zipFile.createZipFile(sourceFile, zipParams);
                          if (log.isDebugEnabled()) {
                              log.debug("Creating: " + sourceFile.getName()
                                      + " to " + zipFile.getFile().getName()
                                      + " Pass: " + getPassword());
                          }
                      }
                  } catch (ZipException e) {
                      log.error(e);
                      status = 1;
                  }
              }
          }
      }
  
      return status;
  }
  </code></pre>