Menu
  • HOME
  • TAGS

How to add hostname to block list after consecutive failures in multithreading application?

java,multithreading,thread-safety,callable,atomicreference

I would associate each host with an AtomicInteger that is incremented on each RestClientException. This integer would be set to zero on a succesful call to enforce the "five consecutive times" constraint. The code would look something like this. private final ConcurrentHashMap<String, AtomicInteger> failedCallCount = new ConcurrentHashMap<>(); void call() {...

Atomic references are unnecessary when using synchronized

java,multithreading,atomicreference

You need to make your first and second fields private and expose those values as synchronized methods. Otherwise reading the fields directly might result in outdated or partially outdated data from BigInteger objects (non-volatile field reads are not thread safe). Then your class will be thread safe. You might try...