⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calcclient.java

📁 java threads 3th源码,包括各个章节的源代码
💻 JAVA
字号:
package javathreads.examples.ch12.example4;import java.io.*;import java.net.*;public class CalcClient extends Thread {    long n;    Socket sock;    public CalcClient(long n, String host, int port) throws UnknownHostException, IOException {        this.n = n;	sock = new Socket(host, port);    }    public void run() {        try {            DataOutputStream dos = new DataOutputStream(sock.getOutputStream());            dos.writeLong(n);            DataInputStream dis = new DataInputStream(sock.getInputStream());            System.out.println("Received answer " + dis.readLong());        } catch (IOException ioe) {            System.out.println("Socket error " + ioe);        }    }    public static void main(String[] args) throws Exception {        int nThreads = Integer.parseInt(args[0]);        long n = Long.parseLong(args[1]);        int port = Integer.parseInt(args[3]);        CalcClient[] clients = new CalcClient[nThreads];        for (int i = 0; i < nThreads; i++) {            clients[i] = new CalcClient(n, args[2], port);            clients[i].start();        }        for (int i = 0; i < nThreads; i++) {            clients[i].join();        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -