トップ «前の日記(2014-02-20) 最新 次の日記(2014-02-22)» 編集

ヨタの日々

2001|08|09|10|11|12|
2002|01|02|03|04|05|06|07|08|09|10|11|12|
2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|12|
2024|01|02|03|04|

2014-02-21 :-)

_ 午前

0530 起床 || 本日は全休

0830 通院 && レントゲンをとるなど && とくに異常なし

1000 散髪

1100 おひる。カップラーメン

_ 午後

1200 アニメ消化

1500 散歩

梅はオワコン

IMG_3897

_

1700 飯。弁当

1800 読書

2000 ぐったり

IMG_3905

_ 私の熱い独身活動 ドクカツ! 始まります! フフッヒ

飯を作る気力がないのでインスタントにするなど怠惰なセイカツをしている。

_ ,

ツッコミ spam 増えたなあ。ksg

_ [Java][Ruby][マルチスレッド][デザインパターン]Java言語で学ぶデザインパターン入門マルチスレッド編 Thread-Per-Message - この仕事、やっといてね

メッセージごとにスレッドを起動して処理する。

(起動済スレッドへメッセージを投げるのは Worker-Thread パターン)

# coding: utf-8

#
# 『増補改訂版Java言語で学ぶデザインパターン入門マルチスレッド編』 http://www.hyuki.com/dp/dp2.html
# 
# Thread-Per-Message - この仕事、やっといてね
#

require 'thread'
require 'monitor'

class Host
  def initialize()
    @helper = Helper.new()
  end
  
  def request(count, c)
    puts "        request(#{count}, #{c}) BEGIN"
    t = Thread.new() {
      @helper.handle(count, c)
    }
    puts "        request(#{count}, #{c}) END"
    return t
  end
end

class Helper
  def handle(count, c)
    puts "        handle(#{count}, #{c}) BEGIN"
    0.upto(count) {|i|
      slowly()
      printf c
    }
    puts ""
    puts "        handle(#{count}, #{c}) END"
  end

  def slowly()
    begin
      sleep(2)
    rescue => ex
      puts ex
    end
  end
end

def main(argv)
  th ||= []
  puts "main BEGIN"
  host = Host.new();
  th << host.request(10, 'A')
  th << host.request(20, 'B')
  th << host.request(30, 'C')
  th.each {|t| t.join()}
  puts "main END"
end

main(ARGV)
>ruby Thread-Per-Message.rb
main BEGIN
        request(10, A) BEGIN
        request(10, A) END
        request(20, B) BEGIN
        request(20, B) END
        request(30, C) BEGIN
        request(30, C) END
        handle(10, A) BEGIN
        handle(20, B) BEGIN
        handle(30, C) BEGIN
ACBCABCABCABCBAACBBCACABCBACABCBA
        handle(10, A) END
BCCBBCCBCBCBBCBCBCB
        handle(20, B) END
CCCCCCCCCCC
        handle(30, C) END
main END

ライセンス

Copyright (C) 2002,2006 Hiroshi Yuki.
http://www.hyuki.com/dp/dp2.html
hyuki@hyuki.com

This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim
that you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is not
required.

2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.

3. This notice may not be removed or altered from any source distribution.

参考

『増補改訂版Java言語で学ぶデザインパターン入門マルチスレッド編』

4797331623