Author Topic: Thread Safe  (Read 4250 times)

Kevin

  • Newbie
  • *
  • Posts: 1
    • View Profile
Thread Safe
« on: September 06, 2012, 05:18:38 PM »
Can multiple threads read and write to the zip file at the same time without blowing up?

admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 403
    • View Profile
Re: Thread Safe
« Reply #1 on: September 09, 2012, 10:04:30 PM »
This can be quite tricky to implement, if not impossible to achieve, especially when using encryption or when compressing the file (and not just using the store method, which just copies the source file to the zip without any compression). A current block of file being compressed/decompressed depends on the previous block. So, if multiple threads were to read or write, these threads cannot do this process simultaneously, but have to wait until the block n-1 (if n is the current block) is read/wrote. So, its as good as running the process in the same thread.

Writing different files in different threads to a zip file (each thread handling a unique file in the zip) can be tricky as well. For example: AES encryption requires a unique number (as part of salt calculation) for each file in the zip. And another example: if a zip file is being created and multiple number of files being added (with compression), then the second thread, which will start writing the second file to the zip should know exactly at which location in the zip file to start writing, and this cannot be determined until the first thread is done writing.

Some compression algorithms, like LZMA/LZMA2, support multithreading. Unfortunately, these compression methods are not supported by Zip4j at the moment.

tewsuccess

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Thread Safe
« Reply #2 on: September 14, 2015, 01:02:30 PM »

What everyone seems to have heard a bit. This is because I was never the same.

 


Warning: Cannot modify header information - headers already sent in /home/content/66/5374066/html/zip4j/forum/Sources/Errors.php on line 346

Warning: Cannot modify header information - headers already sent in /home/content/66/5374066/html/zip4j/forum/Sources/Errors.php on line 347

Warning: Cannot modify header information - headers already sent in /home/content/66/5374066/html/zip4j/forum/Sources/Errors.php on line 348

Warning: Cannot modify header information - headers already sent in /home/content/66/5374066/html/zip4j/forum/Sources/Errors.php on line 351

Warning: Cannot modify header information - headers already sent in /home/content/66/5374066/html/zip4j/forum/Sources/Errors.php on line 352

Warning: Cannot modify header information - headers already sent in /home/content/66/5374066/html/zip4j/forum/Sources/Errors.php on line 353
Connection Problems

Connection Problems

Sorry, SMF was unable to connect to the database. This may be caused by the server being busy. Please try again later.