Skip to content

Instantly share code, notes, and snippets.

@marinat
Created November 11, 2013 14:24
Show Gist options
  • Save marinat/7413882 to your computer and use it in GitHub Desktop.
Save marinat/7413882 to your computer and use it in GitHub Desktop.
public class Generator {
private static final Map<byte[], byte[]> cache = new HashMap<byte[], byte[]>();
public static byte[] generate(byte[] src) {
byte[] generated = cache.get(src);
if (generated == null) {
synchronized (cache) {
generated = cache.get(src);
if (generated == null) {
generated = doGenerate(src);
cache.put(src, generated);
}
}
}
return generated;
}
private static byte[] doGenerate(byte[] src) {...}
// ...
}
Подробнее: http%3A%2F%2Fcompany.yandex.ru%2Fjob%2Fvacancies%2Fandroidspb.xml
@formatq
Copy link

formatq commented Nov 11, 2013

все плохо

@mishaAe
Copy link

mishaAe commented Nov 11, 2013

Используй java.util.concurrent.ConcurrentHashMap

@formatq
Copy link

formatq commented Nov 11, 2013

не используй byte[] как ключ в HashMap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment