This class extends Raster to provide pixel writing capabilities.
Refer to the class comment for Raster for descriptions of how
a Raster stores pixels.
The constructors of this class are protected. To instantiate
a WritableRaster, use one of the createWritableRaster factory methods
in the Raster class.
Creates a Raster based on a BandedSampleModel with the
specified DataBuffer, width, height, scanline stride, bank
indices, and band offsets. The number of bands is inferred
from bankIndices.length and bandOffsets.length, which must be
the same. The upper left corner of the Raster is given by the
location argument. If location is null, (0, 0) will be used.
Creates a Raster based on a BandedSampleModel with the
specified data type, width, height, scanline stride, bank
indices and band offsets. The number of bands is inferred from
bankIndices.length and bandOffsets.length, which must be the
same.
The upper left corner of the Raster is given by the
location argument. The dataType parameter should be one of the
enumerated values defined in the DataBuffer class.
The only dataTypes supported currently are TYPE_BYTE, TYPE_USHORT,
and TYPE_INT.
Creates a Raster based on a BandedSampleModel with the
specified data type, width, height, and number of bands.
The upper left corner of the Raster is given by the
location argument. If location is null, (0, 0) will be used.
The dataType parameter should be one of the enumerated values
defined in the DataBuffer class.
The only dataTypes supported currently are TYPE_BYTE, TYPE_USHORT,
and TYPE_INT.
Returns a new Raster which shares all or part of this Raster's
DataBuffer. The new Raster will possess a reference to the
current Raster, accessible through its getParent() method.
The parentX, parentY, width and height parameters
form a Rectangle in this Raster's coordinate space,
indicating the area of pixels to be shared. An error will
be thrown if this Rectangle is not contained with the bounds
of the current Raster.
The new Raster may additionally be translated to a
different coordinate system for the plane than that used by the current
Raster. The childMinX and childMinY parameters give the new
(x, y) coordinate of the upper-left pixel of the returned
Raster; the coordinate (childMinX, childMinY) in the new Raster
will map to the same pixel as the coordinate (parentX, parentY)
in the current Raster.
The new Raster may be defined to contain only a subset of
the bands of the current Raster, possibly reordered, by means
of the bandList parameter. If bandList is null, it is taken to
include all of the bands of the current Raster in their current
order.
To create a new Raster that contains a subregion of the current
Raster, but shares its coordinate system and bands,
this method should be called with childMinX equal to parentX,
childMinY equal to parentY, and bandList equal to null.
Create a compatible WritableRaster the same size as this Raster with
the same SampleModel and a new initialized DataBuffer.
Create a compatible WritableRaster with the specified size, a new
SampleModel, and a new initialized DataBuffer.
Create a compatible WritableRaster with the specified
location (minX, minY) and size (width, height), a
new SampleModel, and a new initialized DataBuffer.
Create a compatible WritableRaster with location (minX, minY)
and size (width, height) specified by rect, a
new SampleModel, and a new initialized DataBuffer.
Creates a Raster based on a PixelInterleavedSampleModel with the
specified DataBuffer, width, height, scanline stride, pixel
stride, and band offsets. The number of bands is inferred from
bandOffsets.length. The upper left corner of the Raster
is given by the location argument. If location is null, (0, 0)
will be used.
Note that interleaved DataBuffer.TYPE_INT
Rasters are not supported. To create a 1-band Raster of type
DataBuffer.TYPE_INT
, use
Raster.createPackedRaster().
Creates a Raster based on a PixelInterleavedSampleModel with the
specified data type, width, height, scanline stride, pixel
stride, and band offsets. The number of bands is inferred from
bandOffsets.length.
The upper left corner of the Raster is given by the
location argument. If location is null, (0, 0) will be used.
The dataType parameter should be one of the enumerated values
defined in the DataBuffer class.
Note that interleaved DataBuffer.TYPE_INT
Rasters are not supported. To create a 1-band Raster of type
DataBuffer.TYPE_INT
, use
Raster.createPackedRaster().
The only dataTypes supported currently are TYPE_BYTE
and TYPE_USHORT.
Creates a Raster based on a PixelInterleavedSampleModel with the
specified data type, width, height, and number of bands.
The upper left corner of the Raster is given by the
location argument. If location is null, (0, 0) will be used.
The dataType parameter should be one of the enumerated values
defined in the DataBuffer class.
Note that interleaved DataBuffer.TYPE_INT
Rasters are not supported. To create a 1-band Raster of type
DataBuffer.TYPE_INT
, use
Raster.createPackedRaster().
The only dataTypes supported currently are TYPE_BYTE
and TYPE_USHORT.
Creates a Raster based on a SinglePixelPackedSampleModel with
the specified DataBuffer, width, height, scanline stride, and
band masks. The number of bands is inferred from bandMasks.length.
The upper left corner of the Raster is given by
the location argument. If location is null, (0, 0) will be used.
Creates a Raster based on a MultiPixelPackedSampleModel with the
specified DataBuffer, width, height, and bits per pixel. The upper
left corner of the Raster is given by the location argument. If
location is null, (0, 0) will be used.
Creates a Raster based on a SinglePixelPackedSampleModel with
the specified data type, width, height, and band masks.
The number of bands is inferred from bandMasks.length.
The upper left corner of the Raster is given by the
location argument. If location is null, (0, 0) will be used.
The dataType parameter should be one of the enumerated values
defined in the DataBuffer class.
The only dataTypes supported currently are TYPE_BYTE, TYPE_USHORT,
and TYPE_INT.
Creates a Raster based on a packed SampleModel with the
specified data type, width, height, number of bands, and bits
per band. If the number of bands is one, the SampleModel will
be a MultiPixelPackedSampleModel.
If the number of bands is more than one, the SampleModel
will be a SinglePixelPackedSampleModel, with each band having
bitsPerBand bits. In either case, the requirements on dataType
and bitsPerBand imposed by the corresponding SampleModel must
be met.
The upper left corner of the Raster is given by the
location argument. If location is null, (0, 0) will be used.
The dataType parameter should be one of the enumerated values
defined in the DataBuffer class.
The only dataTypes supported currently are TYPE_BYTE, TYPE_USHORT,
and TYPE_INT.
Creates a Raster with the specified SampleModel and DataBuffer.
The upper left corner of the Raster is given by the location argument.
If location is null, (0, 0) will be used.
Create a Raster with the same size, SampleModel and DataBuffer
as this one, but with a different location. The new Raster
will possess a reference to the current Raster, accessible
through its getParent() method.
Returns a new WritableRaster which shares all or part of this
WritableRaster's DataBuffer. The new WritableRaster will
possess a reference to the current WritableRaster, accessible
through its getParent() and getWritableParent() methods.
The parentX, parentY, width and height parameters form a
Rectangle in this WritableRaster's coordinate space, indicating
the area of pixels to be shared. An error will be thrown if
this Rectangle is not contained with the bounds of the current
WritableRaster.
The new WritableRaster may additionally be translated to a
different coordinate system for the plane than that used by the current
WritableRaster. The childMinX and childMinY parameters give
the new (x, y) coordinate of the upper-left pixel of the
returned WritableRaster; the coordinate (childMinX, childMinY)
in the new WritableRaster will map to the same pixel as the
coordinate (parentX, parentY) in the current WritableRaster.
The new WritableRaster may be defined to contain only a
subset of the bands of the current WritableRaster, possibly
reordered, by means of the bandList parameter. If bandList is
null, it is taken to include all of the bands of the current
WritableRaster in their current order.
To create a new WritableRaster that contains a subregion of
the current WritableRaster, but shares its coordinate system
and bands, this method should be called with childMinX equal to
parentX, childMinY equal to parentY, and bandList equal to
null.
Creates a WritableRaster with the specified SampleModel and DataBuffer.
The upper left corner of the Raster is given by the location argument.
If location is null, (0, 0) will be used.
Creates a WritableRaster with the specified SampleModel.
The upper left corner of the Raster is given by the location argument.
If location is null, (0, 0) will be used.
Create a WritableRaster with the same size, SampleModel and DataBuffer
as this one, but with a different location. The new WritableRaster
will possess a reference to the current WritableRaster, accessible
through its getParent() and getWritableParent() methods.
Indicates whether some other object is "equal to" this one.
The equals
method implements an equivalence relation
on non-null object references:
- It is reflexive: for any non-null reference value
x
, x.equals(x)
should return
true
.
- It is symmetric: for any non-null reference values
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
- It is transitive: for any non-null reference values
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
- It is consistent: for any non-null reference values
x
and y
, multiple invocations of
x.equals(y) consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
- For any non-null reference value
x
,
x.equals(null)
should return false
.
The equals method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode method, which states
that equal objects must have equal hash codes.
Returns the bounding Rectangle of this Raster. This function returns
the same information as getMinX/MinY/Width/Height.
Returns the runtime class of an object. That Class
object is the object that is locked by static synchronized
methods of the represented class.
Returns the DataBuffer associated with this Raster.
Returns the pixel data for the specified rectangle of pixels in a
primitive array of type TransferType.
For image data supported by the Java 2D API, this
will be one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT,
or DataBuffer.TYPE_DOUBLE. Data may be returned in a packed format,
thus increasing efficiency for data transfers.
An ArrayIndexOutOfBoundsException may be thrown
if the coordinates are not in bounds. However, explicit bounds
checking is not guaranteed.
A ClassCastException will be thrown if the input object is non null
and references anything other than an array of TransferType.
Returns data for a single pixel in a primitive array of type
TransferType. For image data supported by the Java 2D(tm) API,
this will be one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT,
or DataBuffer.TYPE_DOUBLE. Data may be returned in a packed format,
thus increasing efficiency for data transfers.
An ArrayIndexOutOfBoundsException may be thrown
if the coordinates are not in bounds. However, explicit bounds
checking is not guaranteed.
A ClassCastException will be thrown if the input object is non null
and references anything other than an array of TransferType.
Returns the height in pixels of the Raster.
Returns the minimum valid X coordinate of the Raster.
Returns the minimum valid Y coordinate of the Raster.
Returns the number of bands (samples per pixel) in this Raster.
Returns the number of data elements needed to transfer one pixel
via the getDataElements and setDataElements methods. When pixels
are transferred via these methods, they may be transferred in a
packed or unpacked format, depending on the implementation of the
underlying SampleModel. Using these methods, pixels are transferred
as an array of getNumDataElements() elements of a primitive type given
by getTransferType(). The TransferType may or may not be the same
as the storage data type of the DataBuffer.
Returns the parent Raster (if any) of this Raster or null.
Returns the samples in an array of double for the specified pixel.
An ArrayIndexOutOfBoundsException may be thrown
if the coordinates are not in bounds. However, explicit bounds
checking is not guaranteed.
Returns the samples in an array of float for the
specified pixel.
An ArrayIndexOutOfBoundsException may be thrown
if the coordinates are not in bounds. However, explicit bounds
checking is not guaranteed.
Returns the samples in an array of int for the specified pixel.
An ArrayIndexOutOfBoundsException may be thrown
if the coordinates are not in bounds. However, explicit bounds
checking is not guaranteed.
Returns a double array containing all samples for a rectangle of pixels,
one sample per array element.
An ArrayIndexOutOfBoundsException may be thrown
if the coordinates are not in bounds. However, explicit bounds
checking is not guaranteed.
Returns a float array containing all samples for a rectangle of pixels,
one sample per array element.
An ArrayIndexOutOfBoundsException may be thrown
if the coordinates are not in bounds. However, explicit bounds
checking is not guaranteed.
Returns an int array containing all samples for a rectangle of pixels,
one sample per array element.
An ArrayIndexOutOfBoundsException may be thrown
if the coordinates are not in bounds. However, explicit bounds
checking is not guaranteed.
Returns the sample in a specified band for the pixel located
at (x,y) as an int.
An ArrayIndexOutOfBoundsException may be thrown
if the coordinates are not in bounds. However, explicit bounds
checking is not guaranteed.
Returns the sample in a specified band
for a pixel located at (x,y) as a double.
An ArrayIndexOutOfBoundsException may be thrown
if the coordinates are not in bounds. However, explicit bounds
checking is not guaranteed.
Returns the sample in a specified band
for the pixel located at (x,y) as a float.
An ArrayIndexOutOfBoundsException may be thrown
if the coordinates are not in bounds. However, explicit bounds
checking is not guaranteed.
Returns the SampleModel that describes the layout of the image data.
Returns the X translation from the coordinate system of the
SampleModel to that of the Raster. To convert a pixel's X
coordinate from the Raster coordinate system to the SampleModel
coordinate system, this value must be subtracted.
Returns the Y translation from the coordinate system of the
SampleModel to that of the Raster. To convert a pixel's Y
coordinate from the Raster coordinate system to the SampleModel
coordinate system, this value must be subtracted.
Returns the samples for a specified band for a specified rectangle
of pixels in a double array, one sample per array element.
An ArrayIndexOutOfBoundsException may be thrown
if the coordinates are not in bounds. However, explicit bounds
checking is not guaranteed.
Returns the samples for a specified band for the specified rectangle
of pixels in a float array, one sample per array element.
An ArrayIndexOutOfBoundsException may be thrown
if the coordinates are not in bounds. However, explicit bounds
checking is not guaranteed.
Returns the samples for a specified band for the specified rectangle
of pixels in an int array, one sample per array element.
An ArrayIndexOutOfBoundsException may be thrown
if the coordinates are not in bounds. However, explicit bounds
checking is not guaranteed.
Returns the TransferType used to transfer pixels via the
getDataElements and setDataElements methods. When pixels
are transferred via these methods, they may be transferred in a
packed or unpacked format, depending on the implementation of the
underlying SampleModel. Using these methods, pixels are transferred
as an array of getNumDataElements() elements of a primitive type given
by getTransferType(). The TransferType may or may not be the same
as the storage data type of the DataBuffer. The TransferType will
be one of the types defined in DataBuffer.
Returns the width in pixels of the Raster.
Returns the parent WritableRaster (if any) of this WritableRaster,
or else null.
Returns a hash code value for the object. This method is
supported for the benefit of hashtables such as those provided by
java.util.Hashtable
.
The general contract of hashCode
is:
- Whenever it is invoked on the same object more than once during
an execution of a Java application, the hashCode method
must consistently return the same integer, provided no information
used in equals comparisons on the object is modified.
This integer need not remain consistent from one execution of an
application to another execution of the same application.
- If two objects are equal according to the equals(Object)
method, then calling the
hashCode
method on each of
the two objects must produce the same integer result.
- It is not required that if two objects are unequal
according to the
method, then calling the hashCode method on each of the
two objects must produce distinct integer results. However, the
programmer should be aware that producing distinct integer results
for unequal objects may improve the performance of hashtables.
As much as is reasonably practical, the hashCode method defined by
class Object does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the
JavaTM programming language.)
Wakes up a single thread that is waiting on this object's
monitor. If any threads are waiting on this object, one of them
is chosen to be awakened. The choice is arbitrary and occurs at
the discretion of the implementation. A thread waits on an object's
monitor by calling one of the
wait
methods.
The awakened thread will not be able to proceed until the current
thread relinquishes the lock on this object. The awakened thread will
compete in the usual manner with any other threads that might be
actively competing to synchronize on this object; for example, the
awakened thread enjoys no reliable privilege or disadvantage in being
the next thread to lock this object.
This method should only be called by a thread that is the owner
of this object's monitor. A thread becomes the owner of the
object's monitor in one of three ways:
- By executing a synchronized instance method of that object.
- By executing the body of a
synchronized
statement
that synchronizes on the object.
- For objects of type
Class,
by executing a
synchronized static method of that class.
Only one thread at a time can own an object's monitor.
Wakes up all threads that are waiting on this object's monitor. A
thread waits on an object's monitor by calling one of the
wait
methods.
The awakened threads will not be able to proceed until the current
thread relinquishes the lock on this object. The awakened threads
will compete in the usual manner with any other threads that might
be actively competing to synchronize on this object; for example,
the awakened threads enjoy no reliable privilege or disadvantage in
being the next thread to lock this object.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
Sets the data for a rectangle of pixels from a
primitive array of type TransferType. For image data supported by
the Java 2D API, this will be one of DataBuffer.TYPE_BYTE,
DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE. Data in the array
may be in a packed format, thus increasing efficiency for data
transfers.
An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds, or if inData is not large enough to hold the pixel data.
However, explicit bounds checking is not guaranteed.
A ClassCastException will be thrown if the input object is not null
and references anything other than an array of TransferType.
Sets the data for a single pixel from a
primitive array of type TransferType. For image data supported by
the Java 2D(tm) API, this will be one of DataBuffer.TYPE_BYTE,
DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE. Data in the array
may be in a packed format, thus increasing efficiency for data
transfers.
An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds, or if inData is not large enough to hold the pixel data.
However, explicit bounds checking is not guaranteed.
A ClassCastException will be thrown if the input object is not null
and references anything other than an array of TransferType.
Sets the data for a rectangle of pixels from an input Raster.
The input Raster must be compatible with this WritableRaster
in that they must have the same number of bands, corresponding bands
must have the same number of bits per sample, the TransferTypes
and NumDataElements must be the same, and the packing used by
the getDataElements/setDataElements must be identical.
An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
However, explicit bounds checking is not guaranteed.
Sets a pixel in the DataBuffer using a double array of samples for input.
An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
However, explicit bounds checking is not guaranteed.
Sets a pixel in the DataBuffer using a float array of samples for input.
An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
However, explicit bounds checking is not guaranteed.
Sets a pixel in the DataBuffer using an int array of samples for input.
An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
However, explicit bounds checking is not guaranteed.
Sets all samples for a rectangle of pixels from a double array containing
one sample per array element.
An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
However, explicit bounds checking is not guaranteed.
Sets all samples for a rectangle of pixels from a float array containing
one sample per array element.
An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
However, explicit bounds checking is not guaranteed.
Sets all samples for a rectangle of pixels from an int array containing
one sample per array element.
An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
However, explicit bounds checking is not guaranteed.
Copies pixels from Raster srcRaster to this WritableRaster.
For each (x, y) address in srcRaster, the corresponding pixel
is copied to address (x+dx, y+dy) in this WritableRaster,
unless (x+dx, y+dy) falls outside the bounds of this raster.
srcRaster must have the same number of bands as this WritableRaster.
The copy is a simple copy of source samples to the corresponding
destination samples. For details, see
.
Copies pixels from Raster srcRaster to this WritableRaster. Each pixel
in srcRaster is copied to the same x,y address in this raster, unless
the address falls outside the bounds of this raster. srcRaster
must have the same number of bands as this WritableRaster. The
copy is a simple copy of source samples to the corresponding destination
samples.
If all samples of both source and destination Rasters are of
integral type and less than or equal to 32 bits in size, then calling
this method is equivalent to executing the following code for all
x,y
addresses valid in both Rasters.
Raster srcRaster;
WritableRaster dstRaster;
for (int b = 0; b < srcRaster.getNumBands(); b++) {
dstRaster.setSample(x, y, b, srcRaster.getSample(x, y, b));
}
Thus, when copying an integral type source to an integral type
destination, if the source sample size is greater than the destination
sample size for a particular band, the high order bits of the source
sample are truncated. If the source sample size is less than the
destination size for a particular band, the high order bits of the
destination are zero-extended or sign-extended depending on whether
srcRaster's SampleModel treats the sample as a signed or unsigned
quantity.
When copying a float or double source to an integral type destination,
each source sample is cast to the destination type. When copying an
integral type source to a float or double destination, the source
is first converted to a 32-bit int (if necessary), using the above
rules for integral types, and then the int is cast to float or
double.
Sets a sample in the specified band for the pixel located at (x,y)
in the DataBuffer using a double for input.
An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
However, explicit bounds checking is not guaranteed.
Sets a sample in the specified band for the pixel located at (x,y)
in the DataBuffer using a float for input.
An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
However, explicit bounds checking is not guaranteed.
Sets a sample in the specified band for the pixel located at (x,y)
in the DataBuffer using an int for input.
An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
However, explicit bounds checking is not guaranteed.
Sets the samples in the specified band for the specified rectangle
of pixels from a double array containing one sample per array element.
An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
However, explicit bounds checking is not guaranteed.
Sets the samples in the specified band for the specified rectangle
of pixels from a float array containing one sample per array element.
An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
However, explicit bounds checking is not guaranteed.
Sets the samples in the specified band for the specified rectangle
of pixels from an int array containing one sample per array element.
An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
However, explicit bounds checking is not guaranteed.
Returns a string representation of the object. In general, the
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
Causes current thread to wait until another thread invokes the
method or the
method for this object.
In other words, this method behaves exactly as if it simply
performs the call
wait(0).
The current thread must own this object's monitor. The thread
releases ownership of this monitor and waits until another thread
notifies threads waiting on this object's monitor to wake up
either through a call to the notify
method or the
notifyAll
method. The thread then waits until it can
re-obtain ownership of the monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are
possible, and this method should always be used in a loop:
synchronized (obj) {
while (<condition does not hold>)
obj.wait();
... // Perform action appropriate to condition
}
This method should only be called by a thread that is the owner
of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
Causes current thread to wait until either another thread invokes the
method or the
method for this object, or a
specified amount of time has elapsed.
The current thread must own this object's monitor.
This method causes the current thread (call it T) to
place itself in the wait set for this object and then to relinquish
any and all synchronization claims on this object. Thread T
becomes disabled for thread scheduling purposes and lies dormant
until one of four things happens:
- Some other thread invokes the notify method for this
object and thread T happens to be arbitrarily chosen as
the thread to be awakened.
- Some other thread invokes the notifyAll method for this
object.
- Some other thread interrupts
thread T.
- The specified amount of real time has elapsed, more or less. If
timeout is zero, however, then real time is not taken into
consideration and the thread simply waits until notified.
The thread
T is then removed from the wait set for this
object and re-enabled for thread scheduling. It then competes in the
usual manner with other threads for the right to synchronize on the
object; once it has gained control of the object, all its
synchronization claims on the object are restored to the status quo
ante - that is, to the situation as of the time that the
wait
method was invoked. Thread
T then returns from the
invocation of the
wait method. Thus, on return from the
wait method, the synchronization state of the object and of
thread
T is exactly as it was when the
wait method
was invoked.
A thread can also wake up without being notified, interrupted, or
timing out, a so-called spurious wakeup. While this will rarely
occur in practice, applications must guard against it by testing for
the condition that should have caused the thread to be awakened, and
continuing to wait if the condition is not satisfied. In other words,
waits should always occur in loops, like this one:
synchronized (obj) {
while (<condition does not hold>)
obj.wait(timeout);
... // Perform action appropriate to condition
}
(For more information on this topic, see Section 3.2.3 in Doug Lea's
"Concurrent Programming in Java (Second Edition)" (Addison-Wesley,
2000), or Item 50 in Joshua Bloch's "Effective Java Programming
Language Guide" (Addison-Wesley, 2001).
If the current thread is
interrupted
by another thread
while it is waiting, then an InterruptedException is thrown.
This exception is not thrown until the lock status of this object has
been restored as described above.
Note that the wait method, as it places the current thread
into the wait set for this object, unlocks only this object; any
other objects on which the current thread may be synchronized remain
locked while the thread waits.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
Causes current thread to wait until another thread invokes the
method or the
method for this object, or
some other thread interrupts the current thread, or a certain
amount of real time has elapsed.
This method is similar to the wait
method of one
argument, but it allows finer control over the amount of time to
wait for a notification before giving up. The amount of real time,
measured in nanoseconds, is given by:
1000000*timeout+nanos
In all other respects, this method does the same thing as the
method
of one argument. In particular,
wait(0, 0) means the same thing as wait(0).
The current thread must own this object's monitor. The thread
releases ownership of this monitor and waits until either of the
following two conditions has occurred:
- Another thread notifies threads waiting on this object's monitor
to wake up either through a call to the
notify
method
or the notifyAll
method.
- The timeout period, specified by
timeout
milliseconds plus nanos
nanoseconds arguments, has
elapsed.
The thread then waits until it can re-obtain ownership of the
monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are
possible, and this method should always be used in a loop:
synchronized (obj) {
while (<condition does not hold>)
obj.wait(timeout, nanos);
... // Perform action appropriate to condition
}
This method should only be called by a thread that is the owner
of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.