• 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

    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.

  • 相关阅读:
    monit安装配置
    php新加扩展模块
    centos6.5(64bit),python2.6.6安装MySQLdb模块
    esxi导出ovf模板注意事项
    gateone安装使用
    centos7上安装nagios及增加监控服务器
    zabbix自动发现主机并加入组绑定模板
    zabbix监控Windows-server
    zabbix设置中文并解决乱码问题
    centos7安装zabbix客户端并监控
  • 原文地址:https://www.cnblogs.com/Christen/p/5375740.html
Copyright © 2020-2023  润新知