Chapter 10 I/O
10.1 InputStream & OutputStream
a new 'try' edition:
try (InputStream input = src; OutputStream output = dest) {
byte[] data = new byte[1024];
int length;
while ((length = input.read(data)) != -1) {
output.write(data, 0, length);
}
}
try ( ... ) :
http://www.oschina.net/question/12_10706
how to set program arguments in IDEA:
Run --> Edit Condigurations --> (Application) Configuration --> Program arguments
Chapter 11 Tread & Parallel API
11.1 Tread
The way to add 'CPU' is to create Thread instance, then start() it.
1 . Runnable
Every time running it, the result is different.
2 . Thread
For tortoise & hare, change 'implements Runnable' into 'extends Thread'. The main class are as follows:
Thread life cycle
1 . Daemon Thread
None output
We can see the result. Magical.
2 . Runnable, Blocked, Running
We can set priority using 'setPriority()', in which the value ranges from 1 (Thread.MIN_PRIORITY) to 10 (Thread.MAX_PRIORITY). The default is 5 (Thread.NORM_PRIORITY). If not, IllegalArgumentException will be thrown.
To enter Blocked state:
Thread.sleep(),
wait(),
I/O,
...
When a thread is in 'Blocked', another thread call its interrupt() can wake it up, leaving the blocked state.
3 . join()
Current thread will stop until the joined thread ends.
4 . stop
thread.stop() is not recommended. Stop, suspend, resume should operated according to the requires, but not to call these method directly.