88 lines
7.8 KiB
HTML
88 lines
7.8 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html lang="en-us" xml:lang="en-us">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="security" content="public" />
|
|
<meta name="Robots" content="index,follow" />
|
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
|
<meta name="DC.Type" content="concept" />
|
|
<meta name="DC.Title" content="Java threads" />
|
|
<meta name="abstract" content="A thread is a single independent stream that runs within a program. Java is a multithreaded programming language, so more than one thread may be running within the Java virtual machine at one time. Java threads provide a way for a Java program to perform multiple tasks at the same time. A thread is essentially a flow of control in a program." />
|
|
<meta name="description" content="A thread is a single independent stream that runs within a program. Java is a multithreaded programming language, so more than one thread may be running within the Java virtual machine at one time. Java threads provide a way for a Java program to perform multiple tasks at the same time. A thread is essentially a flow of control in a program." />
|
|
<meta name="DC.Relation" scheme="URI" content="platform.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="appsappl.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="javavirm.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="jarfile.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="sunjdk.htm" />
|
|
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
|
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
|
|
<meta name="DC.Format" content="XHTML" />
|
|
<meta name="DC.Identifier" content="threads" />
|
|
<meta name="DC.Language" content="en-us" />
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
|
<title>Java threads</title>
|
|
</head>
|
|
<body id="threads"><a name="threads"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Java threads</h1>
|
|
<div><p>A thread is a single independent stream that runs within a program. Java™ is
|
|
a multithreaded programming language, so more than one thread may be running
|
|
within the Java virtual machine at one time. Java threads
|
|
provide a way for a Java program to perform multiple tasks at
|
|
the same time. A thread is essentially a flow of control in a program.</p>
|
|
<p>Threads are a modern programming construct that are used to support concurrent
|
|
programs and to improve the performance and scalability of applications. Most
|
|
programming languages support threads through the use of add-in programming
|
|
libraries. Java supports threads as built-in application program
|
|
interfaces (APIs).</p>
|
|
<div class="note"><span class="notetitle">Note:</span> The use of threads provides the support to increase the interactivity,
|
|
meaning a shorter wait at the keyboard because more tasks are running in parallel.
|
|
But, the program is not necessarily more interactive just because it has threads.</div>
|
|
<p>Threads are the mechanism for waiting on long running interactions, while
|
|
still allowing the program to handle other work. Threads have the ability
|
|
to support multiple flows through the same code stream. They are sometimes
|
|
called <strong>lightweight processes</strong>. The Java language includes direct support for
|
|
threads. But, by design, it does not support asynchronous non-blocking input
|
|
and output with interrupts or multiple wait.</p>
|
|
<p>Threads allow the development of parallel programs that scale well in an
|
|
environment where a machine has multiple processors. If properly constructed,
|
|
they also provide a model for handling multiple transactions and users.</p>
|
|
<p>You can use threads in a Java program for a number of situations.
|
|
Some programs must be able to engage in multiple activities and still be able
|
|
to respond to additional input from the user. For example, a Web browser should
|
|
be able to respond to user input while playing a sound.</p>
|
|
<p>Threads can also use asynchronous methods. When you call a second method,
|
|
you do not have to wait for the first method to complete before the second
|
|
method continues with its own activity.</p>
|
|
<p>There are also many reasons not to use threads. If a program uses inherently
|
|
sequential logic, one thread can accomplish the entire sequence. Using multiple
|
|
threads in such a case results in a complex program with no benefits. There
|
|
is considerable work in creating and starting a thread. If an operation involves
|
|
only a few statements, it is faster to handle it in a single thread. This
|
|
can be true even when the operation is conceptually asynchronous. When multiple
|
|
threads share objects, the objects must synchronize to coordinate thread access
|
|
and maintain consistency. Synchronization adds complexity to a program, is
|
|
difficult to tune for optimal performance, and can be a source of programming
|
|
errors.</p>
|
|
<p>For more threads information, see <a href="../rzahw/rzahwovepo.htm" target="_blank">Developing multithreaded applications</a>.</p>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="platform.htm" title="The Java platform is the environment for developing and managing Java applets and applications. It consists of three primary components: the Java language, the Java packages, and the Java virtual machine.">Java platform</a></div>
|
|
</div>
|
|
<div class="relconcepts"><strong>Related concepts</strong><br />
|
|
<div><a href="appsappl.htm" title="An applet is a Java program designed to be included in an HTML Web document. You can write your Java applet and include it in an HTML page, much in the same way an image is included. When you use a Java-enabled browser to view an HTML page that contains an applet, the applet's code is transferred to your system and is run by the browser's Java virtual machine.">Java applets and applications</a></div>
|
|
<div><a href="javavirm.htm" title="The Java virtual machine is a runtime environment that you can add into a web browser or any operating system, such as IBM i5/OS. The Java virtual machine runs instructions that a Java compiler generates. It consists of a bytecode interpreter and runtime that allow Java class files to run on any platform, regardless of the platform on which they were originally developed.">Java virtual machine</a></div>
|
|
<div><a href="jarfile.htm" title="A Java ARchive (JAR) file is a file format that combines many files into one. The Java environment differs from other programming environments in that the Java compiler does not generate machine code for a hardware-specific instruction set. Instead, the Java compiler converts Java source code into Java virtual machine instructions, which Java class files store. You can use JAR files to store class files. The class file does not target a specific hardware platform, but instead targets the Java virtual machine architecture.">Java JAR and class files</a></div>
|
|
<div><a href="sunjdk.htm" title="The Java Development Kit (JDK) is software that is distributed by Sun Microsystems, Inc. for Java developers. It includes the Java interpreter, Java classes, and Java development tools: compiler, debugger, disassembler, appletviewer, stub file generator, and documentation generator.">Sun Microsystems, Inc. Java Development Kit</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |