lundi 13 janvier 2020

A Static semaphore is a bad idea?

I have one class A that it can be called by reflection. This class in its exposed public method create an instance of class MAKER that it download a txt file and save it. I want to download and save the txt file in synchronized way, but I have no control on who call A. I have thought to create a static semaphore into Maker class and acquire the lock before start the download process and release that only after the file is saved. In this way I think there is only one Maker class that can download and write file. Is there a better and clean method ?





Aucun commentaire:

Enregistrer un commentaire