Im developing an application based on Spring and JSF 2.0. There is a requirement to remember how many times client from specific ip address tried to submit form during last 3 minutes. If during 3 minutes more than 3 submit attempts were recorded then captcha should be displayed.
Im thinking about using ConcurrentMap<String, ConcurrentLinkedQueue<Long>>
for storing ip address ( String
) and submit time (milis) in queue ( ConcurrentLinkedQueue<Long>
). The queue will be cleaned by Quartz in 3-min intervals (milis older than 3-min will be removed). To check if display captcha I will check if queue size > 3.
Is this correct approach? Do you have any better ideas?
Java provides a special class for storing IP addresses: java.net.InetAddress
. Unlike Long
, it is capable of handling 128-bit addresses in addition to 32-bit ones, and it is not as wasteful as a String
in terms of the memory that it uses, which might become important in very high-volume situations.
Personally, I store my IP's as Longs rather than Strings.
You will see a performance improvement.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.