Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to learn about Threads, Especially in Java [closed]

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!

like image 891
Javed Ahamed Avatar asked Mar 09 '10 02:03

Javed Ahamed


People also ask

How do I make sure a thread is closed in Java?

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.

Can a thread close itself?

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.

What is blocked thread in Java?

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.


3 Answers

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

enter image description here

like image 73
Uri Avatar answered Nov 14 '22 23:11

Uri


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.

like image 33
duffymo Avatar answered Nov 14 '22 23:11

duffymo


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.

like image 39
Rahul Avatar answered Nov 14 '22 21:11

Rahul