( , " " ), , .)
In addition, if this happens often, you want to use Executor(thread pool) instead of manually creating your own Thread- creating / deleting threads is expensive.
I also ignore exception handling in this snippet (which is not completely trivial.)
Runnable runnable = new Runnable() {
public void run() {
InetAddress serverAddr = InetAddress.getByName(serverAddress);
String hostname = serverAddr.getCanonicalHostName();
Socket socket = new Socket(new InetSocketAddress(serverAddr, portNumber), 3000);
}
};
Thread t = new Thread(runnable);
t.start();
Jared source
share