?? _socketchannel.java
字號:
package org.pool;import java.io.IOException;import java.net.InetSocketAddress;import java.net.Socket;import java.net.SocketAddress;import java.nio.ByteBuffer;import java.nio.channels.SocketChannel;import java.nio.channels.spi.SelectorProvider;public class _SocketChannel { /** * 連接狀態(tài) */ private boolean status = true; public SocketChannel socketChannel; public _SocketChannel(InetSocketAddress inetSocketAddress) throws IOException { socketChannel = SocketChannel.open(); socketChannel.configureBlocking(false); socketChannel.connect(inetSocketAddress); } /** * 判斷此連接是否空閑 * * @return boolean 空閑返回ture,否則false */ public boolean isFree() { return status; } /** * 當(dāng)使用此連接的時候設(shè)置狀態(tài)為false(忙碌) */ public void setBusy() { this.status = false; } /** * 當(dāng)客戶端關(guān)閉連接的時候狀態(tài)設(shè)置為true(空閑) */ public void close() { System.out.println("Close : set the status is free "); status = true; } public void destroy() { // Close socket connection close(); // System.out.println(Close success ); } }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -