トップ «前の日記(2014-03-04) 最新 次の日記(2014-03-06)» 編集

ヨタの日々

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|05|06|07|08|09|10|11|

2014-03-05 :-(

_ 午前

0530 起床

0710 食堂

0830 出勤 || テストしTARI

_ 午後

1300 テストしTARI

_

1700 退勤 && 定時過ぎてから現象が再現するなんてよくあること

1800 ぐったり

2100 飯

_ [Java][Ruby][マルチスレッド][デザインパターン]Java言語で学ぶデザインパターン入門マルチスレッド編 Thread-Specific Storage - スレッドごとのコインロッカー

スレッドごとの保存領域。

# coding: utf-8

#
# 『増補改訂版Java言語で学ぶデザインパターン入門マルチスレッド編』 http://www.hyuki.com/dp/dp2.html
# 
# Thread-Specific Storage - スレッドごとのコインロッカー
#

require 'thread'
require 'monitor'

class TSLog
  def initialize(filename)
    @writer = nil
    
    begin
      @writer = File.open(filename, "w")
    rescue => ex
      puts ex
    end
  end
  
  def println(s)
    @writer.puts(s)
  end
  
  def close()
    @writer.puts("==== End of log ====")
    @writer.close()
  end
end

class Log
  # ログを書く
  def self.println(name, s)
    getTSLog(name).println(s)
  end

  # ログを閉じる
  def self.close(name)
    getTSLog(name).close()
  end

  # スレッド固有のログを得る
  def self.getTSLog(name)
    tsLog = Thread.current.thread_variable_get(name)
    
    # そのスレッドからの呼び出しがはじめてなら、新規作成して登録する
    if tsLog == nil
      tsLog = TSLog.new("#{name}-log.txt")
      Thread.current.thread_variable_set(name, tsLog)
    end
    return tsLog
  end
end

class ClientThread < Thread
  def initialize(name)
    @name = name
    
    block = Proc.new {
      puts "#{@name} BEGIN"
      0.upto(10) {|i|
          Log.println(@name, "i = #{i}")
          begin
            sleep(1)
          rescue => ex
            puts ex
          end
      }
      Log.close(@name)
      puts "#{@name} END"
    }
    super(&block)
  end
end

def main(argv)
  th ||= []
  th << ClientThread.new("Alice")
  th << ClientThread.new("Bobby")
  th << ClientThread.new("Chris")
  th.each {|t| t.join() }
end

main(ARGV)
>ruby Thread-Specific-Storage.rb
Alice BEGIN
Bobby BEGIN
Chris BEGIN
Bobby END
Chris END
Alice 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

_ 買い物

iTune Store

とくさん、2007年の Twitter 忘年会[ 20071208#p04 ]で挨拶しただけだけどスンマセン