序列化反序列化
socket 網路通訊
scala 函式式程式設計
輸入輸出流操作
object sender
task.
setvalue1
(522
) task.
setvalue2
(123
) task.
setop
(op)
//寫物件到socket
objectout.
writeobject
(task)
// 重新整理
objectout.
flush()
println
("task 傳送到 processor ..."
)//關閉輸出流
socket.
shutdownoutput()
//接收
val objectinput =
newobjectinputstream
(socket.
getinputstream()
) val obj = objectinput.
readobject()
val responsetask = obj.asinstanceof[task]
//輸出計算結果
println
("sender 收到的結果是:"
+ responsetask.result)
//關閉流
objectinput.
close()
objectout.
close()
socket.
close()
}}
object processor
}
class
task
extends
serializable
def setvalue2
(value2: int)
= def setop
(op:
(int, int)
=> int)
= def setresult
(result : int)
=}
processor
processor 收到 task, 處理 task ...
處理器處理完畢, 計算的結果是:
7
sender
task 傳送到 processor ...
sender 收到的結果是:7
實現乙個簡易的執行緒池。
定義四個類 乙個內部類 乙個任務類 乙個測試類 乙個執行緒池類包含乙個內部類。任務類 任務類,檢查埠。author administrator public class scannertask public void starttask catch unknownhostexception e ca...
C 實現乙個簡易的執行緒池
工作中需要用到多執行緒,就簡單實現了乙個簡易的執行緒池,直接上 記錄一下 ifndef threadpool h define threadpool h include include include include include include class threadpool endif th...
乙個String類的建簡易實現
其中比較重要的那幾個建構函式和析構函式 如果能夠把ostream的過載寫出來將會更加流弊 class string public string const char str null 建構函式 加分項 以下內容加const很重要 string const string other 拷貝構造 stri...