Java??Socket??????????????
???????????? ???????[ 2013/9/26 14:32:21 ] ????????
????4. ??????
????????????5????:
????1?? ??? (Thread t = new Thread())
????2?? ?? (t.start())
????3?? ????
????4?? ????
????????block???????????: ???IO?????? sleep()?? ??????????????
????5??????
????5.?????????????????????: ????????????????????synchronized
?????????????:
??????????????????synchronized?????????????????????????????????????synchronized????????????????????????????????????synchronized?????????????????????????????????????????????????????? ??????????????????????ж???????
????6.synchronized?????
?????????????????????????????飬??????????????????synchronized??????????????????synchronized????顣???£?????this??????????
public void function()
{
doSomething();
//???·???????????
synchronized (this)
{
doCriticalStuff();
moreCriticalStuff();
}
doSomeOtherThing();
}
????7.???????????Socket????????:
??????????????????:
/**
* @author notifier
* @create 2010-9-25 ????10:12:10
* @version 1.0
*/
public class DailyAdviceClient
{
public static void main(String[] args)
{
DailyAdviceClient client = new DailyAdviceClient();
client.receiveMsg();
}
public void receiveMsg()
{
try
{
// 1.????Socket????????Server??IP??????????
Socket socket = new Socket("127.0.0.1"?? 4242);
// 2.????InputStreamReader????????socket??????
InputStreamReader stream = new InputStreamReader(socket
.getInputStream());
// 3.???BufferedReader??????????
BufferedReader br = new BufferedReader(stream);
// 4.????????
String line = null;
while ((line = br.readLine()) != null)
{
System.out.println("Today's advice is: " + line);
}
// 5. ?????????BufferedReader
br.close();
} catch (UnknownHostException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
}
}
??????

???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11