Skip to Content
Java™ Phrasebook
book

Java™ Phrasebook

by Timothy Fisher
November 2006
Intermediate to advanced
224 pages
3h 29m
English
Sams
Content preview from Java™ Phrasebook

Starting a Thread

public class MyThread extends Thread {
											public void run() {
											// do some work
											}
											}
											// code to use MyThread
											new MyThread().start();

There are two primary techniques for writing code that will run in a separate thread. You can either implement the java.lang.Runnable interface or extend the java.lang.Thread class. With either approach, you must implement a run() method. The run() method contains the code that you want to execute in the thread. In this phrase, we have extended the java.lang.Thread class. At the point where we want to start the thread, we instantiate our MyThread class and call the start() method, which is inherited from the Thread class.

Here, we show how running a thread is accomplished using the other technique of ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Ruby Phrasebook

Ruby Phrasebook

Jason Clinton
Wicked Cool Java

Wicked Cool Java

Brian D. Eubanks
Just Java™ 2

Just Java™ 2

Peter van der Linden
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz

Publisher Resources

ISBN: 0768668255Purchase book