SiliCompressor icon indicating copy to clipboard operation
SiliCompressor copied to clipboard

The compressed file was the same when using multi-thread.

Open DennisGuo opened this issue 5 years ago • 0 comments

In my case :

  1. Choose 9 images .
  2. Create 9 thread to compress images.
  3. Some compressed file was same ( !!! this is wrong).

What wrong ? When I debug the code, I find the compressed cache file name was same :

  • The files before compressed 20190919152129.png

  • The files after compressed 20190919152209.png

I guess the author did not consider the situation when the multi-thread start at the same time.

The issue was caused by the code below:

com.iceteck.silicompressorr.SiliCompressor line: 223

    /**
     * Get the file path of the compressed file
     *
     * @param filename
     * @param file     Destination directory
     * @return
     */
    private String getFilename(String filename, File file) {
        if (!file.exists()) {
            file.mkdirs();
        }
        String ext = ".jpg";
        //get extension
        /*if (Pattern.matches("^[.][p][n][g]", filename)){
            ext = ".png";
        }*/

        return (file.getAbsolutePath() + "/IMG_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()) + ext);

    }

DennisGuo avatar Sep 19 '19 07:09 DennisGuo