Java Reference
In-Depth Information
os.arch: x86
line.separator:
file.separator: \
user.name: Jeff Friesen
java.version: 1.7.0
java.home: C:\Program Files\Java\jdk1.7.0\jre
Note
line.separator
stores the actual line separator character/characters,
not its/their representation (such as
\r\n
), which is why a blank line appears after
line.separator:
.
Threading
Applicationsexecutevia
threads
,whichareindependentpathsofexecutionthroughan
application's code. When multiple threads are executing, each thread's path can differ
fromotherthreadpaths.Forexample,athreadmightexecuteoneofaswitchstatement's
cases, and another thread might execute another of this statement's cases.
Note
Applicationsusethreadstoimproveperformance.Someapplicationscanget
bywithonlythedefaultmainthreadtocarryouttheirtasks,butotherapplicationsneed
additional threads to perform time-intensive tasks in the background, so that they re-
main responsive to their users.
TheJVMgiveseachthreaditsownmethod-callstacktopreventthreadsfrominter-
feringwitheachother.Separatestacksletthreadskeeptrackoftheirnextinstructionsto
execute,whichcandifferfromthreadtothread.Thestackalsoprovidesathreadwithits
own copy of method parameters, local variables, and return value.
JavasupportsthreadsviaitsThreadingAPI.ThisAPIconsistsofoneinterface(
Run-
nable
) and four classes (
Thread
,
ThreadGroup
,
ThreadLocal
, and
Inher-
itableThreadLocal
) in the
java.lang
package. After exploring
Runnable
and
Thread
(andmentioning
ThreadGroup
duringthisexploration),thissectionex-
plores thread synchronization,
ThreadLocal
, and
InheritableThreadLocal
.
Note
Java 5 introduced the
java.util.concurrent
package as a high-level
Although
java.util.concurrent
isthepreferredAPIforworkingwiththreads,
you should also be somewhat familiar with Threading because it is helpful in simple