concurrency - Java Download Concurrent Data -


I am developing an app that downloads map tiles around different locations in a city. To do this, I have a thread for each location in which I select the tile and make a thread to download each.

Well, the question is how to avoid thread for a tile that already exists. Thread Pool

It should not be just checking that the file exists, because it is possible That thread for that tile already exists (secondly, the tile is needed from the other place), but the file is not created -

Any thoughts? Thank you

You ConcurrentHashMap & lt; Tile, thread & gt; in which you store all downloader threads.

Before you start it, add a thread to hashmap and delete it before deleting it. Surely you will check the hashup for a specific tile before starting a thread for that tile.

This is my simplest solution that comes to my mind, it will be easy to implement, but you have to read carefully how to use this type of hamster, in which there is no compatibility problems with guaranteed concurrency

You can also use the "Set" feature of the hamsterpap

  Collections.newSetFromMap (new concurrent hashmap  ())  

In this way you will not have any association tile -> Red but only a structure for which you have a set.contains (tile) are to check what has been prescribed by a thread tile first.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -