20145109 《Java程序设计》第六周学习总结

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

829945-20160410215759406-1359441558.png

829945-20160410215809718-809691750.png

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:

829945-20160410215922156-861957207.png

Thread life cycle

1 . Daemon Thread

829945-20160412164634957-513123399.png

None output

829945-20160412164651113-2006719304.png

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.

829945-20160412175029238-1314233711.png

829945-20160412175043082-1734005604.png

4 . stop

thread.stop() is not recommended. Stop, suspend, resume should operated according to the requires, but not to call these method directly.

转载于:https://www.cnblogs.com/Christen/p/5375740.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值