I have always been kind of confused by threads, and my class right now makes heavy use of them. We are using java.util.concurrent but I don't even really get the basics. UpDownLatch, Futures, Executors; these words just fly over my head. Can you guys suggest any resources to help learn what I need from the ground up?
Thanks a lot in advance!
Modern ways to suspend/stop a thread are by using a boolean flag and Thread. interrupt() method. Using a boolean flag: We can define a boolean variable which is used for stopping/killing threads say 'exit'. Whenever we want to stop a thread, the 'exit' variable will be set to true.
A thread automatically terminates when it returns from its entry-point routine. A thread can also explicitly terminate itself or terminate any other thread in the process, using a mechanism called cancelation.
Blocking methods in java are the particular set of methods that block the thread until its operation is complete. So, they will have to block the current thread until the condition that fulfills their task is satisfied. Since, in nature, these methods are blocking so-called blocking methods.
I'm assuming that you already went through the Java tutorial's threading chapter?
There are many good books on threading in general, but also specifically in Java.
For example, Java Concurrency in Practice
Read "Java Concurrency In Practice" by Brian Goetz. Great book.
Or Doug Lea's "Concurrent Programming In Java". Old school, terrific stuff. Pre-dates the concurrent package, but it's the basis for a lot of it.
If you are looking for a beginners book, check out Java Thread Programming by Paul Hyde . The other books like "Java Concurrency in Practice" and "Concurent Programming in Java" can be read to get an in depth understanding of concurrency (and specially the new java.util.concurent API) but may not be good for beginners.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With