问题
I've created a program that parses html pages. I use jsoup connect function within a callable class inside ThreadPool. The problem is that I'm connecting to the same website and with a thread pool size of 5+, I get IO Exceptions - 400 errors.
How do I not make that happen?
回答1:
If you're getting a 400 HTTP response, check the content of the response for an error message. A 400 means a bad request of some kind: you didn't include all the required information or included malformed information. Some people also use it as kind of a catch-all for when the client did something they don't like. If you're making lots of different requests, examine the ones that caused 400's to see if there's something wrong with them. If they all look right or if you're sending the same requests repeatedly, then maybe the site you're hitting has some kind of rate limiting that disallows you from making too many concurrent requests or too many requests within a particular timeframe. If it's something like that, I'd expect there to be a message in the response telling you what's going on.
来源:https://stackoverflow.com/questions/6885076/400-http-errors-using-jsoup-in-multithreaded-program