Thread thread=new Thread(serviceThread);
while(true){??
????????????????socket=ss.accept();??
????????????????//為每個(gè)客戶開啟一個(gè)線程??
????????????????ServiceThread?serviceThread=new?ServiceThread(socket);??
????????????????Thread?thread=new?Thread(serviceThread);??
????????????????thread.start(); ?
? 直接serviceThread.start()可以嗎? ? ? 和這個(gè)有什么區(qū)別?看視頻里是直接serverthread.start()的
2016-11-19
視頻中ServerThread是繼承Thread類
所以可以直接調(diào)用start方法
如果你的ServerThread是實(shí)現(xiàn)Runnable接口
那就必須new一個(gè)thread把接口實(shí)現(xiàn)類裝在進(jìn)來