Java threads ebook

Multi thread programming is built into Java, but you need a clear view of Java thread management, synchronization and control to write thread safe programs.

The Java threads ebook explains how Thread and Runnable classes work to run threaded programs and makes sense of run(), start(), wait() and sleep() methods.

What if you were One Percent Better with Java threads?

  • You're eager to write your next Runnable class
  • You use threads like gift wrap for your apps
  • Thread safety has meaning, the volatile keyword has purpose
  • You sleep easily with thread methods, not run in fear
  • You know when to synchronize, when to wait and notify

Java threads FAQ

Java threads FAQ ebook by Philip Shaw

ISBN
EPUB: 978-1-907863-07-3
Mobi: 978-1-907863-20-2

Introduces the Java thread management scheme, how to create threads and run multi-threaded programs, make a thread sleep and wait. Discusses thread safety concerns, thread priority and the worker thread design pattern.

» More about the Java threads ebook below

Buy now

Mobi for Amazon Kindle

EPUB for Apple iPad, Sony Reader, Nook

What's inside the Java threads ebook?

We keep standard publishing blurb to a minimum and put it at the back. The book starts with a brief introduction, then straight into:

  • 27 core Java thread questions and answers
  • 10 extra Java threads answers from other FAQs
  • Links for online updates

You get updates to this edition free by email.

Java threads ebook contents

The Java threads FAQ ebook helps you solve problems like these.

Threads and runnable types

What's the difference between Thread and Runnable types?
Learn how threads and runnable classes work in multi-threaded programs.
What is a Runnable object and a Runnable argument?
These simple pointers on the use of runnables should clear confusion.
How does the run() method in Runnable work?
Get threaded programs to carry on running with a continuous run method.
A Thread is runnable, how does that work?
Find out where the run method belongs in your program and how it works with threads.
Do Thread and Runnable types have their own run() methods?
There's a special bond that passes between a runnable and a thread, and a simple explanation.
Why not override Thread to make a Runnable?
You don't have to write a threaded program in a thread, and there's good reason to avoid it.
When could I adapt the Thread class though?
Resist the urge to put all thread code in a single class, aim for clean thread programming.

The start() method

What's the difference between a thread's start() and run() methods?
If your start() method only runs once, you need to learn how the start method works.
Can I implement my own start() method?
If you're not sure where to start a threaded program, don't start()!

Thread management methods

Which class is the wait() method defined in?
The wait() method is in the perfect place to make a thread wait.
Which class is the sleep(long) method defined in?
Make a thread sleep and you will begin to see how thread management works.
Why are wait(), notify() and notifyall() methods defined in the Object class?
Thread scheduling demands that any class may have to wait for a condition to become true.
Why are there separate wait and sleep methods?
Do your threaded programs wait for ever? It may be time to use the sleep() method.

Multi-threaded design questions

If all methods are synchronized, is a class thread safe?
The synchronized keyword is not the last word in thread safety.
Do I need to use synchronized on setValue(int)?
Don't synchronize every method, find the appropriate level of thread control.
How do I create a Runnable with inheritance?
Implement a basic runnable that extends an existing class.
What is the volatile modifier for?
When a variable never matches a test condition, the volatile keyword may be the answer.
What is the SwingUtilities.invokeLater(Runnable) method for?
Take your first steps with multi threaded techniques in a GUI application.
Which has priority with a static synchronized thread?
Choose the right monitor object to prevent unexpected behaviour in static methods.

Multi-threaded design patterns

What is a working thread?
Could a worker thread pool be the answer to your problem?

Thread programming jargon

What is a green thread?
Old Java books talk about green threads, see if they are relevant to your project.
What are native operating system threads?
See how operating system threads work with Java.

Thread programming problems

I get “incompatible return type” for my thread's getState() method!
A Java SDK update may be the cause of your thread problems.
Apache Log4J has thrown a ThreadDeath error!
Sounds serious, but what is a thread death error and what to do?

Extra Java threads answers

The Java threads ebook includes 10 extra Java thread-related answers from ten other Java FAQs.

  • Is the DriverManager thread safe?
  • Is the Struts 1.x Action thread safe or not?
  • Does JSP support multi-threading?
  • How many objects exist when a JSP has concurrent requests?
  • Why do we only use the main() method to start a program?
  • How can I find the inherited attributes of a class?
  • How can I count the number of instances of an object?
  • How does the JVM execute a servlet compared with a regular Java class?
  • What is the difference between Hashtable and HashMap?

Any more questions?

Please contact us about the Java threads FAQ ebook.

One Percent Better ebook stockists

One Percent Better ebooks are stocked at Amazon in Mobi format for the Kindle, the Apple iBookstore and Google eBookstore in EPUB format.

Kindle editions at Amazon

One Percent Better ebooks are distributed through Amazon for direct download to your Kindle. Search for “Java threads FAQ”.

iPad ebooks at the iBookstore

One Percent Better ebooks are also distributed through the Apple iBookstore for direct download to your iPad. Search for “Java threads FAQ”.

EPUB editions at the Google eBookstore

One Percent Better ebooks are distributed through the Google eBookstore in EPUB format. Search for “Java threads FAQ”.

 

Ebooks for Web developers

More titles coming soon, contact us for news.