I learnt Java back in university. It's been 4 years since I last coded Java. I develop PHP applic开发者_JAVA技巧ations mainly. This time I need a language with more powerful concurrency support. I thought to myself, I'll just revise my Java in an hour and I'm ready to go.
As it turned out, there is no human friendly tutorials (!!) that can be easily found. I searched "java tutorial" and the first results are either impossibly abstract with no useful code examples or ad-filled spit outs of the Web 1.0 era! More complex searches just led me to more confusing/outdated posts. I just love PHP for the numerous friendly tutorials out there.
Anyway, to avoid making this a pointless post, can anyone direct me to a readable tutorial to how I can use the thread ExecutorService to 1) queue a few thousand Runnables, 2) have a maximum of 15 threads executing at a time, and 3) if a thread fails, re-queue it or just don't remove it from the Executor's pool.
Thank you in advance!
It's from 2006, but still pretty decent: http://math.hws.edu/javanotes/
this should work for you
Executors.newFixedThreadPool(15)
15 threads fixed, not max. but it's no big deal to have 15 idle threads.
regarding tutorials: good tutorials are very hard to write, and generally there is NO reward.
regarding concurrency: it is very difficult. people spend years just to understand the basics. you shouldn't be surprised if a few hours is needed to understand a concurrency issue.
If you dislike Times New Roman, just change the browser default font to Tahoma or something like.
Then start here and click your way through Next link. Then there are the API docs, each with examples in the introductory text. E.g. ExecutorService
. Then there are books, like Concurrency in Practice.
精彩评论