THE Java™ Programming Language, Fourth Edition
You can remove part of the buffer with delete, which takes a starting and ending index. The segment of the string up to but not ...
13.4.3. Capacity Management The buffer of a StringBuilder object has a capacity, which is the length of the string it can store ...
Exercise 13.5: Write a method to convert strings containing decimal numbers into comma-punctuated numbers, with a comma every th ...
Johann Wolfgang von Goethe Chapter 14. Threads At some point, you have to jump out of the plane under the assumption that you ca ...
Inside a computer, the analogue to having multiple real-world bank tellers is called multithreading. A thread, like a bank telle ...
with an object to tell when the object is or is not being used. Many real-world software problems can best be solved by using mu ...
private String word; // what word to print private int delay; // how long to pause public PingPong(String whatToSay, int delayTi ...
14.2. Using Runnable Threads abstract the concept of a workeran entity that gets something done. The work done by a thread is pa ...
object is then created for each object and is started immediately. Five Thread constructors enable you to specify a Runnable obj ...
} } When a PrintServer is created, it creates a new Thread to do the actual printing and passes itself as the Runnable instance. ...
Exercise 14.2: Modify the first version of PrintServer so that only the thread created in the constructor can successfully execu ...
Locks are owned per thread, so invoking a synchronized method from within another method synchronized on the same object will pr ...
You can ask whether the current thread holds the lock on a given object by passing that object to the Thread class's static hold ...
Here is a method to replace each element in an array with its absolute value, relying on a synchronized statement to control acc ...
synchronized (lockB) { bVal = val; } } public void reset() { synchronized (lockA) { synchronized (lockB) { aVal = bVal = 0.0; } ...
The synchronized statement in the constructor acquires the lock of the Class object for Body in the same way a synchronized stat ...
needed. In the case of operations on multiple objects, where could you put a synchronized method? In these situations, the abili ...
Everything is executed within synchronized code. If it were not, the state of the object would not be stable. For example, if th ...
throws InterruptedException { while (queue.size() == 0) wait(); // Wait for a print job return queue.remove(); } } In contrast t ...
Notifies all the threads waiting for a condition to change. Threads will return from the wait invocation once they can reacquire ...
«
10
11
12
13
14
15
16
17
18
19
»
Free download pdf