标签:java art ar line new 服务器 网络 程序
一、客户端读/写
Socket s = new Socket("127.0.0.1",5000); InputStreamReader stream = new InputStreamReader(s.getInputStream()); BufferedReader reader = new BufferedReader(stream); String message = reader.readLine();
PrintWriter writer = new PrintWrite(s.getOutputStream());//写到客户端上 writer.println("Send:");
ServerSocket s = new ServerSocket(5000); Socket sock = s.accept();
public class MyRunnable implements Runnalbe{ @override public void run(){...} } class ThreadTest{ public static void main(String [] args){ Runnable threadJob = new MyRunnable(); Thread myThread = new Thread(threadJob); myThread.start(); } }
Thread.sleep(2000);//一定程度上可以让线程按照预想的顺序执行在线程中执行的方法,需要避免死锁,在关键的地方上加上synchronized来让方法或者程序块变成原子性
标签:java art ar line new 服务器 网络 程序
原文地址:http://blog.csdn.net/fengxiaoke_fxk/article/details/38235431