Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File decompression uses new class StringKeeper to make sure a file is… #22

Merged
merged 2 commits into from
Aug 21, 2018

Conversation

craigrose
Copy link

… being handled only by one thread at a time

* @author cmrose
*/

public class StringKeeper {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is now called StringLocker

private List stringList = Collections.synchronizedList(new ArrayList<String>());
private boolean waiting = false;

public synchronized void control(String item) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will block all threads trying to control an item not just ones trying to access the item won't it? (only one thread can be running this particular bit of code at a time) Will have the desired effect still but is overly restrictive. Could have just added synchronized to makeUncompressed above to do this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the wait() will cause the thread to wait and to no longer be synchronised on the the object thus allowing another thread to come in and add a file to the list. https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait This is evidenced to be the case by the fact that I observe more than one file appearing in the list at any given time.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks for the explanation. Can see how that works now.

}
}

stringKeeper.release(filename);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better in a single try finally block so we always know its going to be released?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done so in the second commit. There was already a try..catch in the method that calls makeUncompressed (getRaf) which I added the finally to.

Move calls to stringLocker.control() and stringLocker.release() into try..catch..finally in NetcdfFile.getRaf for
more easily read code and guaranteed release of the lock.
@jonescc jonescc merged commit b65d5a0 into 4.6.x-imos Aug 21, 2018
@jonescc jonescc deleted the unzipping_download-reading_cache-race branch August 21, 2018 06:34
@craigrose craigrose restored the unzipping_download-reading_cache-race branch September 13, 2018 05:37
@craigrose craigrose deleted the unzipping_download-reading_cache-race branch September 13, 2018 06:34
@craigrose craigrose restored the unzipping_download-reading_cache-race branch September 13, 2018 06:37
craigrose added a commit that referenced this pull request Sep 13, 2018
#22)

File decompression uses new class StringLocker to make sure a file is being handled only
by one thread at a time
@craigrose craigrose deleted the unzipping_download-reading_cache-race branch September 13, 2018 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants